Widely availableSupported across all major browsers. Safe to use in production.

Overview

The number type (and Number object) represents floating-point numbers, such as 42 or -4.201, while the Math API contains mathematical functions and constants. JavaScript can also represent boundless negative and positive values as Infinity or not-a-number as NaN (as in 0 * Infinity).

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
1
12
1
1
18
1
Other

The Math namespace object contains static properties and methods for mathematical constants and functions.

1
12
1
1
18
1
Built-in object

The Math.E static data property represents Euler's number, the base of natural logarithms, e, which is approximately 2.718.

1
12
1
1
18
1

The Math.LN10 static data property represents the natural logarithm of 10, approximately 2.303.

1
12
1
1
18
1

The Math.LN2 static data property represents the natural logarithm of 2, approximately 0.693:

1
12
1
1
18
1

The Math.LOG10E static data property represents the base 10 logarithm of e, approximately 0.434.

1
12
1
1
18
1

The Math.LOG2E static data property represents the base 2 logarithm of e, approximately 1.443.

1
12
1
1
18
1

The Math.PI static data property represents the ratio of the circumference of a circle to its diameter, approximately 3.14159.

1
12
1
1
18
1

The Math.SQRT1_2 static data property represents the square root of 1/2, which is approximately 0.707.

1
12
1
1
18
1

The Math.SQRT2 static data property represents the square root of 2, approximately 1.414.

1
12
1
1
18
1

The Math.abs() static method returns the absolute value of a number.

1
12
1
1
18
1

The Math.acos() static method returns the inverse cosine (in radians) of a number. That is,

1
12
1
1
18
1

The Math.acosh() static method returns the inverse hyperbolic cosine of a number. That is,

38
12
25
8
38
8

The Math.asin() static method returns the inverse sine (in radians) of a number. That is,

1
12
1
1
18
1

The Math.asinh() static method returns the inverse hyperbolic sine of a number. That is,

38
12
25
8
38
8

The Math.atan() static method returns the inverse tangent (in radians) of a number, that is

1
12
1
1
18
1

The Math.atan2() static method returns the angle in the plane (in radians) between the positive x-axis and the ray from (0, 0) to the point (x, y), for Math.atan2(y, x).

1
12
1
1
18
1

The Math.atanh() static method returns the inverse hyperbolic tangent of a number. That is,

38
12
25
8
38
8

The Math.cbrt() static method returns the cube root of a number. That is

38
12
25
8
38
8

The Math.ceil() static method always rounds up and returns the smallest integer greater than or equal to a given number.

1
12
1
1
18
1

The Math.clz32() static method returns the number of leading zero bits in the 32-bit binary representation of a number.

38
12
31
7
38
7

The Math.cos() static method returns the cosine of a number in radians.

1
12
1
1
18
1

The Math.cosh() static method returns the hyperbolic cosine of a number. That is,

38
12
25
8
38
8

The Math.exp() static method returns e raised to the power of a number. That is

1
12
1
1
18
1

The Math.expm1() static method returns e raised to the power of a number, subtracted by 1. That is

38
12
25
8
38
8

The Math.floor() static method always rounds down and returns the largest integer less than or equal to a given number.

1
12
1
1
18
1

The Math.fround() static method returns the nearest 32-bit single precision float representation of a number.

38
12
26
8
38
8

The Math.hypot() static method returns the square root of the sum of squares of its arguments. That is,

38
12
27
8
38
8

The Math.imul() static method returns the result of the C-like 32-bit multiplication of the two parameters.

28
12
20
7
28
7

The Math.log() static method returns the natural logarithm (base e) of a number. That is

1
12
1
1
18
1

The Math.log10() static method returns the base 10 logarithm of a number. That is

38
12
25
8
38
8

The Math.log1p() static method returns the natural logarithm (base e) of 1 + x, where x is the argument. That is:

38
12
25
8
38
8

The Math.log2() static method returns the base 2 logarithm of a number. That is

38
12
25
8
38
8

The Math.max() static method returns the largest of the numbers given as input parameters, or -Infinity if there are no parameters.

1
12
1
1
18
1

The Math.min() static method returns the smallest of the numbers given as input parameters, or Infinity if there are no parameters.

1
12
1
1
18
1

The Math.pow() static method returns the value of a base raised to a power. That is

1
12
1
1
18
1

The Math.random() static method returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, with approximately uniform distribution over that range — which you can then scale to your desired range. The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or reset by the…

1
12
1
1
18
1

The Math.round() static method returns the value of a number rounded to the nearest integer.

1
12
1
1
18
1

The Math.sign() static method returns 1 or -1, indicating the sign of the number passed as argument. If the input is 0 or -0, it will be returned as-is.

38
12
25
9
38
9

The Math.sin() static method returns the sine of a number in radians.

1
12
1
1
18
1

The Math.sinh() static method returns the hyperbolic sine of a number. That is,

38
12
25
8
38
8

The Math.sqrt() static method returns the square root of a number. That is

1
12
1
1
18
1

The Math.tan() static method returns the tangent of a number in radians.

1
12
1
1
18
1

The Math.tanh() static method returns the hyperbolic tangent of a number. That is,

38
12
25
8
38
8

The Math.trunc() static method returns the integer part of a number by removing any fractional digits.

38
12
25
8
38
8
Other

The NaN global property is a value representing Not-A-Number.

1
12
1
1
18
1

Number values represent floating-point numbers like 37 or -9.25.

1
12
1
1
18
1
Built-in object

The Number.EPSILON static data property represents the difference between 1 and the smallest floating point number greater than 1.

34
12
25
9
34
9

The Number.MAXSAFEINTEGER static data property represents the maximum safe integer in JavaScript (253 – 1).

34
12
31
9
34
9

The Number.MAX_VALUE static data property represents the maximum numeric value representable in JavaScript.

1
12
1
1
18
1

The Number.MINSAFEINTEGER static data property represents the minimum safe integer in JavaScript, or -(253 - 1).

34
12
31
9
34
9

The Number.MIN_VALUE static data property represents the smallest positive numeric value representable in JavaScript.

1
12
1
1
18
1

The Number.NEGATIVE_INFINITY static data property represents the negative Infinity value.

1
12
1
1
18
1

The Number.NaN static data property represents Not-A-Number, which is equivalent to NaN. For more information about the behaviors of NaN, see the description for the global property.

1
12
1
1
18
1

The Number() constructor creates Number objects. When called as a function, it returns primitive values of type Number.

1
12
1
1
18
1

The Number.POSITIVE_INFINITY static data property represents the positive Infinity value.

1
12
1
1
18
1

The Number.isFinite() static method determines whether the passed value is a finite number — that is, it checks that a given value is a number, and the number is neither positive Infinity, negative Infinity, nor NaN.

19
12
16
9
25
9

The Number.isInteger() static method determines whether the passed value is an integer.

34
12
16
9
34
9

The Number.isNaN() static method determines whether the passed value is the number value NaN, and returns false if the input is not of the Number type. It is a more robust version of the original, global isNaN() function.

25
12
15
9
25
9

The Number.isSafeInteger() static method determines whether the provided value is a number that is a safe integer.

34
12
32
9
34
9

The Number.parseFloat() static method parses an argument and returns a floating point number. If a number cannot be parsed from the argument, it returns NaN.

34
12
25
9
34
9

The Number.parseInt() static method parses a string argument and returns an integer of the specified radix or base.

34
12
25
9
34
9

The toExponential() method of Number values returns a string representing this number in exponential notation.

1
12
1
2
18
1

The toFixed() method of Number values returns a string representing this number using fixed-point notation with the specified number of decimal places.

1
12
1
2
18
1

The toPrecision() method of Number values returns a string representing this number to the specified number of significant digits.

1
12
1
2
18
1

The toString() method of Number values returns a string representing this number value.

1
12
1
1
18
1

The valueOf() method of Number values returns the value of this number.

1
12
1
1
18
1
Other

The isNaN() function determines whether a value is NaN, first converting the value to a number if necessary. Because coercion inside the isNaN() function can be surprising, you may prefer to use Number.isNaN().

1
12
1
1
18
1

The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).

1
12
1
1
18
1
Built-in object
parseInt.leading zero strings as decimal

Parses leading-zero strings as decimal, not octal

23
12
21
6
25
6
Other

Binary number syntax uses a leading zero followed by a lowercase or uppercase Latin letter "B" (0b or 0B). Any character after the 0b that is not 0 or 1 will terminate the literal sequence.

41
12
25
9
41
9

``js-nolint 1234567890 42 ``

1
12
1
1
18
1

Hexadecimal number syntax uses a leading zero followed by a lowercase or uppercase Latin letter "X" (0x or 0X). Any character after the 0x that is outside the range (0123456789ABCDEF) will terminate the literal sequence.

1
12
1
1
18
1

Octal number syntax uses a leading zero followed by a lowercase or uppercase Latin letter "O" (0o or 0O). Any character after the 0o that is outside the range (01234567) will terminate the literal sequence.

41
12
25
9
41
9
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

JAVASCRIPT
Number.isNaN(NaN);      // true
Number.isFinite(42);    // true
Number.parseInt('42px'); // 42

Math.max(1, 5, 3);      // 5
Math.round(4.7);        // 5
Math.random();          // A random number between 0 and 1

Live demo

Random Numbergenerator

random alignnumber generate.. with Math.random Use 1 from 100.

PreviewFullscreen

Safe integer. Check

Number.isSafeInteger Use,. Number that accurate to rangeinside or check..

PreviewFullscreen

Calculationprecision. Verification

0.1 + 0.2 that accurate to 0.3 to current and,. countermeasureexample simulated.

PreviewFullscreen

Use cases

  • Using Math and numbers

    The number type (and Number object) represents floating-point numbers, such as 42 or -4.201, while the Math API contains mathematical functions and constants. JavaScript can also represent boundless negative and positive values as Infinity or not-a-number as NaN (as in 0 * Infinity).

Cautions

  • No specific concerns. Stable across all major browsers.

Accessibility

  • When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.

Powered by web-features