10/11/25, 7:30 AM JavaScript Math Object
Tutorials References Exercises Get Certified
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
JavaScript Math Object
❮ Previous Next ❯
The Math Object
The JavaScript Math object allows you to perform mathematical tasks.
The Math object is static.
All methods and properties can be used without creating a Math object first.
[Link];
Try it Yourself »
Math Properties (Constants)
The syntax for any Math property is : [Link] .
JavaScript provides 8 mathematical constants that can be accessed as Math properties:
Example
Math.E // returns Euler's number
[Link] // returns PI
[Link] 1/12
10/11/25, 7:30 AM JavaScript Math Object
Math.SQRT2 // returns the square root of 2
Tutorials // returns
Math.SQRT1_2 References
the Exercises
square root of 1/2 Get Certified
Math.LN2 // returns the natural logarithm of 2
HTML CSS
Math.LN10 JAVASCRIPT SQLnatural
// returns the PYTHON JAVA
logarithm of 10PHP HOW TO [Link] C
Math.LOG2E // returns base 2 logarithm of E
Math.LOG10E // returns base 10 logarithm of E
Try it Yourself »
Math Methods
The syntax for Math any methods is : [Link](number)
Number to Integer
There are 4 common methods to round a number to an integer:
[Link](x) Returns x rounded to its nearest integer
[Link](x) Returns x rounded up to its nearest integer
[Link](x) Returns x rounded down to its nearest integer
[Link](x) Returns the integer part of x (new in ES6)
[Link]()
[Link](x) returns the nearest integer:
Examples
[Link](4.6);
Try it Yourself »
[Link] 2/12
10/11/25, 7:30 AM JavaScript Math Object
[Link](4.5);
Tutorials References Exercises Get Certified
HTML
Try itCSS
YourselfJAVASCRIPT
» SQL PYTHON JAVA PHP HOW TO [Link] C
[Link](4.4);
Try it Yourself »
[Link]()
[Link](x) returns the value of x rounded up to its nearest integer:
Example
[Link](4.9);
[Link](4.7);
[Link](4.4);
[Link](4.2);
[Link](-4.2);
Try it Yourself »
[Link]()
[Link](x) returns the value of x rounded down to its nearest integer:
Example
[Link](4.9);
[Link](4.7);
[Link](4.4);
[Link](4.2);
[Link](-4.2);
[Link] 3/12
10/11/25, 7:30 AM JavaScript Math Object
Try it Yourself »
Tutorials References Exercises Get Certified
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
[Link]()
[Link](x) returns the integer part of x:
Example
[Link](4.9);
[Link](4.7);
[Link](4.4);
[Link](4.2);
[Link](-4.2);
Try it Yourself »
[Link]()
[Link](x) returns if x is negative, null or positive.
If x is positive it returns 1
If x is negative it returns -1
If x is zero, it returns 0
Example
[Link](-4);
[Link](0);
[Link](4);
Try it Yourself »
[Link] 4/12
10/11/25, 7:30 AM JavaScript Math Object
Tutorials References Exercises Get Certified
Note
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
[Link]() and [Link]() were added to JavaScript 2015 - ES6.
REMOVE ADS
[Link]()
[Link](x, y) returns the value of x to the power of y:
Example
[Link](8, 2);
Try it Yourself »
[Link]()
[Link](x) returns the square root of x:
Example
[Link](64);
Try it Yourself »
[Link]()
[Link] 5/12
10/11/25, 7:30 AM JavaScript Math Object
[Link](x) returns the absolute (positive) value of x:
Tutorials References Exercises Get Certified
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
Example
[Link](-4.7);
Try it Yourself »
[Link]()
[Link](x) returns the sine (a value between -1 and 1) of the angle x (given in radians).
If you want to use degrees instead of radians, you have to convert degrees to radians:
Angle in radians = Angle in degrees x PI / 180.
Example
[Link](90 * [Link] / 180); // returns 1 (the sine of 90 degrees)
Try it Yourself »
[Link]()
[Link](x) returns the cosine (a value between -1 and 1) of the angle x (given in
radians).
If you want to use degrees instead of radians, you have to convert degrees to radians:
Angle in radians = Angle in degrees x PI / 180.
Example
[Link] 6/12
10/11/25, 7:30 AM JavaScript Math Object
[Link](0 * [Link] / 180);
Tutorials References
// returns 1 (the cos of 0 degrees)
Exercises Get Certified
HTML
Try itCSS
YourselfJAVASCRIPT
» SQL PYTHON JAVA PHP HOW TO [Link] C
[Link]() and [Link]()
[Link]() and [Link]() can be used to find the lowest or highest value in a list of
arguments:
Example
[Link](0, 150, 30, 20, -8, -200);
Try it Yourself »
Example
[Link](0, 150, 30, 20, -8, -200);
Try it Yourself »
[Link]()
[Link]() returns a random number between 0 (inclusive), and 1 (exclusive):
Example
[Link]();
Try it Yourself »
[Link] 7/12
10/11/25, 7:30 AM JavaScript Math Object
Tutorials References Exercises Get Certified
You will learn more about [Link]() in the next chapter of this tutorial.
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
The [Link]() Method
[Link](x) returns the natural logarithm of x.
The natural logarithm returns the time needed to reach a certain level of growth:
Examples
[Link](1);
Try it Yourself »
[Link](2);
Try it Yourself »
[Link](3);
Try it Yourself »
Math.E and [Link]() are twins.
How many times must we multiply Math.E to get 10?
[Link](10);
Try it Yourself »
[Link] 8/12
10/11/25, 7:30 AM JavaScript Math Object
The Tutorials
Math.log2()
ReferencesMethod
Exercises Get Certified
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
Math.log2(x) returns the base 2 logarithm of x.
How many times must we multiply 2 to get 8?
Math.log2(8);
Try it Yourself »
The Math.log10() Method
Math.log10(x) returns the base 10 logarithm of x.
How many times must we multiply 10 to get 1000?
Math.log10(1000);
Try it Yourself »
Learn More:
Full Math Reference
?
Exercise
What is a correct syntax for rounding down a number to its nearest integer?
[Link] 9/12
10/11/25, 7:30 AM JavaScript Math Object
[Link](4.9)
Tutorials References Exercises Get Certified
HTML
[Link](4.9)
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
[Link](4.9)
[Link](4.9)
Submit Answer »
❮ Previous Next ❯
COLOR PICKER
[Link] 10/12
10/11/25, 7:30 AM JavaScript Math Object
Tutorials References Exercises Get Certified
HTML
CSS JAVASCRIPT SQL REMOVE
PYTHONADS JAVA PHP HOW TO [Link] C
PLUS SPACES
GET CERTIFIED FOR TEACHERS
FOR BUSINESS CONTACT US
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
[Link] Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
[Link] Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
AngularJS Reference
jQuery Reference
Top Examples Get Certified
[Link] 11/12
10/11/25, 7:30 AM JavaScript Math Object
HTML Examples HTML Certificate
Tutorials CSS Examples
References
JavaScript Examples
Exercises CSS Certificate
Get Certified
JavaScript Certificate
How To Examples Front End Certificate
HTML
CSS SQL Examples SQL
JAVASCRIPT PYTHON JAVA PHP SQLHOW Certificate
TO [Link] C
Python Examples Python Certificate
[Link] Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate
FORUM ABOUT ACADEMY
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and
learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full
correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and
privacy policy.
Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by [Link].
[Link] 12/12