JavaScript Math Property

math in javascript

The JavaScript Math Property allows you to perform mathematical tasks, and includes several properties.


JavaScript Math Property


Methods

Let’s see the list of JavaScript Math methods with description.


Math.sqrt(n)

The JavaScript math.sqrt(n) method returns the square root of the given number.

Square Root of 17 is: <span id="p1"></span>  

<script>  

document.getElementById('p1').innerHTML=Math.sqrt(17);  

</script>  

Math.random()

The JavaScript math.random() method returns the random number between 0 to 1.

Random Number is: <span id="p2"></span>  

<script>  

document.getElementById('p2').innerHTML=Math.random();  

</script> 

Math.pow(m,n)

The JavaScript math.pow(m,n) method returns the m to the power of n that is mn.

3 to the power of 4 is: <span id="p3"></span>  

<script>  

document.getElementById('p3').innerHTML=Math.pow(3,4);  

</script>  

Math.floor(n)

The JavaScript math.floor(n) method returns the lowest integer for the given number. For example 3 for 3.7, 5 for 5.9 etc.

Floor of 4.6 is: <span id="p4"></span>  

<script>  

document.getElementById('p4').innerHTML=Math.floor(4.6);  

</script>  

Math.ceil(n)

The JavaScript math.ceil(n) method returns the largest integer for the given number. For example 4 for 3.7, 6 for 5.9 etc.

Ceil of 4.6 is: <span id="p5"></span>  

<script>  

document.getElementById('p5').innerHTML=Math.ceil(4.6);  

</script>  

Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *