Friday, October 10, 2025
HomeLanguagesJavascriptJavaScript Math Object

JavaScript Math Object

The Javascript Math object is used to perform mathematical operations on numbers. 

Example 1: This example uses math object properties to return their values. 

html




<h1>neveropen</h1>
 
<h2>JavaScript Math Object</h2>
 
<p id="GFG"></p>
 
<!-- Script to return math property values -->
<script>
    document.getElementById("GFG").innerHTML =
        "Math.LN10: " + Math.LN10 + "<br>" +
        "Math.LOG2E: " + Math.LOG2E + "<br>" +
        "Math.Log10E: " + Math.LOG10E + "<br>" +
        "Math.SQRT2: " + Math.SQRT2 + "<br>" +
        "Math.SQRT1_2: " + Math.SQRT1_2 + "<br>" +
        "Math.LN2: " + Math.LN2 + "<br>" +
        "Math.E: " + Math.E + "<br>" +
        "Math.PI: " + Math.PI;
</script>


Output:

  

Example 2: Math object methods are used in this example. 

html




<h1>GeeksForGeeks</h1>
 
<h2>JavaScript Math Object</h2>
 
<p id="GFG" style="color:green;"></p>
 
<!-- Script to use math object method -->
<script>
    document.getElementById("GFG").innerHTML =
    "<p><b>Math.abs(-4.7):</b> " + Math.abs(-4.7) + "</p>" +
    "<p><b>Math.ceil(4.4):</b> " + Math.ceil(4.4) + "</p>" +
    "<p><b>Math.floor(4.7):</b> " + Math.floor(4.7) + "</p>" +
    "<p><b>Math.sin(90 * Math.PI / 180):</b> " +
            Math.sin(90 * Math.PI / 180) + "</p>" +
    "<p><b>Math.min(0, 150, 30, 20, -8, -200):</b> " +
            Math.min(0, 150, 30, 20, -8, -200) + "</p>" +
    "<p><b>Math.random():</b> " + Math.random() + "</p>";
</script>


Output:

 

There are many math object properties which are listed below:

Property Description
Math.E Euler’s number
Math.PI PI
Math.SQRT2 The square root of 2
Math.SQRT1_2 The square root of 1/2
Math.LN2 The natural logarithm of 2
Math.LN10 The natural logarithm of 10
Math.LOG2E Base 2 logarithm of E
Math.LOG10E Base 10 logarithm of E

Math objects: There are many math objects that exist in JavaScript which are listed below:

Methods Description
abs(x) Absolute value of x
acos(x) Arccosine of x, in radian
asin(x) Arcsine of x, in radian
atan(x) Arctangent of x, a numeric value between -PI/2 and PI/2 radian
atan2(y, x) Arctangent of the quotient of its arguments
ceil(x) Value of x rounded up to the nearest integer
cos(x) Cosine of x (x in radians)
exp() Value of E^x
floor() Value of x rounded below to the nearest integer
log() Natural logarithm (base E) of x
max(a, b, …) Highest value
min(a, b, …) Lowest value
pow(x, y) Value of x to power of y
random() Random number between 0 and 1
round(x) Value of x rounded to the nearest integer
sin(x) Sine of x (x in radians)
sqrt(x) Square root of x
tan(x) Tangent of angle
RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS