---
title: "JavaScript-Math Object"  
description: "JavaScript-Math Object"  
author: "Danish Khan"  
published: 2012-10-20  
updated: 2017-11-30  
canonical: https://www.mindstick.com/articles/1049/javascript-math-object  
category: "javascript"  
tags: ["javascript"]  
reading_time: 5 minutes  

---

# JavaScript-Math Object

[Introduction](https://yourviews.mindstick.com/view/85450/mesopotamia-introduction-to-an-ancient-civilization):\

In this article I am going to explain you about Math object which provides us several mathematical functionalities. The Math object allows us to perform common mathematical tasks. It includes several Mathematical constants and [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best). Unlike other global objects Math is not a constructor all methods and [properties](https://yourviews.mindstick.com/view/81845/now-it-s-possible-to-predict-properties-of-any-molecule) of Method are static and all properties and methods of math can be called by using Math as an object without creating it.

##### Syntax for using Math Methods is:

var roundof = Math.round(0.6);

This [function](https://www.mindstick.com/articles/43970/purchase-suitable-wedding-dresses-for-your-wedding-function) will round of the value of 0.6 to 1.

##### Math Methods:

| ## Methods | ## Description |
| --- | --- |
|  |  |
| ## abs () | Returns the absolute value of a number. |
| ## acos() | It returns the arccosine of a number. |
| ## asin() | It returns the arcsine of a number. |
| ## atan() | It returns the arctangent of a number. |
| ## ceil() | It returns the [smallest](https://yourviews.mindstick.com/view/81880/royal-families-of-world-s-smallest-islands-do-fishing) integer greater than or equal to a number. |
| ## floor() | It returns the largest integer less than or equal to a number. |
| ## log() | It returns the Natural logarithm of a number. |
| ## max() | It returns the largest number of zero or more number. |
| ## min() | It returns the smallest of zero or more number. |
| ## round() | It returns the value of a number rounded to the nearest integer. |
| ## sin() | It returns the sine of a number. |
| ## sqrt() | It returns the [square root](https://answers.mindstick.com/qa/104752/how-to-find-the-square-root-in-c) of a number. |
| ## tan() | It returns the tangent of a number. |
| ## toSource() | It returns the string “Math”. |
| ## pow() | It returns the base to the exponent power i.e. base exponent. |

##### Examples depicting the use of the above methods:

#### abs():

```
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript">
        function findAbsValue() {
           var absVal = Math.abs(-2);
            var absNull = Math.abs(null);
            document.write("Absolute value of -2 is : " + absVal + "<br />");
            document.write("Absolute value is of null is : " + absNull + "<br />");
        }
    </script>
</head>
<body onload="findAbsValue()">
</body>
</html>
```

##### Output:

[JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)-Math Object

#### acos():

```
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
  <script type="text/javascript">
     function findAcos() {
         var value = Math.acos(-1);
         document.write("acos value of -1 is: " + value + "<br />");
         var value = Math.acos(null);
  document.write("acos value of Null is: " + value + "<br />");
    }
</script>
</head>
<body onload="findAcos()">
</body>
</html>
```

Output:

JavaScript-Math Object

##### ceil():

```
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Java Script Ceil Method</title>
    <script type="text/javascript">
        function getCeil() {
            var firstval = Math.ceil(55.95);
            document.write("Value is: " + firstval + "<br/>");
            firstval = Math.ceil(-55.95);
            document.write("Value is: " + firstval + "<br/>");
        }
    </script>
</head>
<body onload="getCeil()">
</body>
</html>
```

##### Output:

JavaScript-Math Object

##### floor:

```
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Java Script floor Method</title>
    <script type="text/javascript">
        function getFloor() {
            var firstval = Math.floor(55.95);
            document.write("Value is: " + firstval + "<br/>");
            firstval = Math.floor(-55.95);
            document.write("Value is: " + firstval + "<br/>");
        }
    </script>
</head>
<body onload="getFloor()">
</body>
</html>
```

Output : JavaScript-Math Object

##### round():

```
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript">
        function mathFunction() {
           var roundof = Math.round(0.6);
           document.write("After round of the number is : " + roundof + "<br />");
        }
    </script>
</head>
<body onload="mathFunction()">
</body>
</html>
```

#####

##### Output:

JavaScript-Math Object

#### max():

```
   <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
     <title>Java Script to get the max value</title>
     <script type="text/javascript">
        function getMax() {
            var firstval = Math.max(100, 43, 66, -25);
            document.write("Value is: " + firstval + "<br/>");
        }
     </script>
     </head>
     <body onload="getMax()">
     </body>
     </html>
```

Output: JavaScript-Math Object

####

##### min():

```
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Java Script to get the max value</title>
    <script type="text/javascript">
        function getMin() {
            var firstval = Math.min(100, 43, 66, -25);
            document.write("Minimum Value is: " + firstval + "<br/>");
        }
    </script>
</head>
<body onload="getMin()">
</body>
</html>
```

##### \
Output:

JavaScript-Math Object\

##### Conclusion:

Through this article we came to know about what math function is and how to use its various methods.

\

---

Original Source: https://www.mindstick.com/articles/1049/javascript-math-object

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
