Favorites

JavaScript Math Object

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Math
JavaScript Numbers and Dates · NamespaceThis object is supported by all modern browsers.
Updated 28th November 2026

Math is a built-in object holding mathematical constants, such as Math.PI, and functions, such as Math.round(), Math.max() and Math.random(). It isn't a constructor.

Description

The Math object is a namespace of mathematical constants and functions. You use its members directly, as in Math.PI or Math.sqrt(16); it can't be called or used with new. It covers rounding (round(), floor(), ceil(), trunc()), minimum and maximum, powers and roots, logarithms, trigonometry and random numbers.

All Math functions work with the Number type only, not BigInt. Math.random() is fine for games and visual effects but is not cryptographically secure; use crypto.getRandomValues() for anything security-related.

Commonly used constants include Math.PI, Math.E, Math.SQRT2 and Math.LN2. Trigonometric functions such as Math.sin() and Math.cos() work in radians, so convert degrees with deg * Math.PI / 180. Results are floating point numbers, so values like Math.sin(Math.PI) come out as tiny numbers instead of exactly zero, and you may need to round results before displaying or comparing them.

Syntax

Math.method(value)
Math.CONSTANT

Static properties

NameDescription
Math.EMath.E is Euler's number, the base of natural logarithms, approximately 2.718.
Math.PIMath.PI is the ratio of a circle's circumference to its diameter, approximately 3.14159.

Static methods

NameDescription
Math.abs()The Math.abs() static method returns the absolute value of a number: its distance from zero, without a minus sign.
Math.atan2()The Math.atan2() static method returns the angle from the x axis to a point, which is useful for finding the direction between two points.
Math.cbrt()The Math.cbrt() static method returns the cube root of a number.
Math.ceil()The Math.ceil() static method rounds a number up to the next whole number.
Math.cos()The Math.cos() static method returns the cosine of an angle given in radians.
Math.exp()The Math.exp() static method returns e (Euler's number) raised to a given power.
Math.floor()The Math.floor() static method rounds a number down to the nearest whole number.
Math.hypot()The Math.hypot() static method returns the square root of the sum of squares of its arguments, such as the distance between two points.
Math.log()The Math.log() static method returns the natural logarithm (base e) of a number.
Math.log10()The Math.log10() static method returns the base-10 logarithm of a number.
Math.log2()The Math.log2() static method returns the base-2 logarithm of a number.
Math.max()The Math.max() static method returns the largest of the numbers passed to it.
Math.min()The Math.min() static method returns the smallest of the numbers passed to it.
Math.pow()The Math.pow() static method returns a base number raised to a power.
Math.random()The Math.random() static method returns a pseudo-random decimal number from 0 up to (but not including) 1.
Math.round()The Math.round() static method rounds a number to the nearest whole number.
Math.sign()The Math.sign() static method returns 1, -1 or 0 to show whether a number is positive, negative or zero.
Math.sin()The Math.sin() static method returns the sine of an angle given in radians.
Math.sqrt()The Math.sqrt() static method returns the square root of a number.
Math.tan()The Math.tan() static method returns the tangent of an angle given in radians.
Math.trunc()The Math.trunc() static method removes the decimal part of a number, leaving the whole-number part.

Example

console.log(Math.PI);
console.log(Math.round(4.6), Math.floor(4.6), Math.ceil(4.1));
console.log(Math.max(3, 9, 2));
console.log(Math.sqrt(81), Math.pow(2, 10));
console.log(Math.floor(Math.random() * 6) + 1);   // dice roll

Browser Support

The following information will show you the current browser support for the Math object. Hover over a browser icon to see the version that first introduced support for this object.

This object is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee