We can take help of Math object to perform mathematical operation. Sometime we want to perform mathematical calculation on client side then we use concept of java script Math object. Java Script math object provides some built in function to perform mathematical task. In this demonstration we learn that how to use mathematical function in java script.

Some commonly used Math function in Java Script
  •  Math.PI  :   Math.PI property gives value of PI.
  • Math.sqrt(<value>)  : Math.sqrt(<value>) method returns square root of number passed to its parameter.
  • Math.round(<double value>)   : Math.round(<double value>) returns an round of value of given decimal value. Such as round of value of 5.7 is 6.
  • Math.random()   :  Math.random() method return random number which is greater than 0 and less than 1.
Following function provides a demonstration to use Java Script Math object
<script type="text/javascript">
        function mathLibrary() {
            document.write("Value Of Pie is--->  : " + Math.PI + "<br />");
            document.write("Squareroot of 81 is---->  : " + Math.sqrt(81) + "<br />");
            document.write("Value of Sin 60 is---->  :  " + Math.sin(60) + "<br />");
            document.write("Round of 5.7 is --->   : " + Math.round(5.7) + "<br />");
            document.write("Random number generated by Java Script is---->  :" + Math.random() + "<br />");
Output of the following code snippet is as follows

Math Object in Java Script

  Modified On Mar-22-2018 07:08:13 AM

Leave Comment