ECMAScript Built-in Constants and Functions About Mathematics

Shen Lu
Shen Lu
Posted on Feb 08, 2024
8 min read (1431 words)

ECMAScript Global Object for Mathematics

A plenty of built-in objects in ECMAScript can be directly used as mathematical constants and functions.

Value Properties

Value PropertiesDescriptionNotationValue (Number)
Infinitypositive Infinity++\inftyInfinity (+Infinity)
NaNNot a NumberNaNNaNNaN

Function Properties

Function PropertiesDescriptionReturn Type
isFinite(number)determine whether a number is a finite number or not (Number.isFinite(Number(number)))boolean
isNaN(number)determine whether a value is NaN or not (Number(number) !== Number(number))boolean
parseFloat(string)parse an argument to a floating point numbernumber (float)
parseInt(string, radix)parse an argument to an integer of the specified radixnumber (integer)

Constructor Properties

  • BigInt: A built-in object whose constructor returns a bigint primitive (or BigInt)to represent whole numbers larger than 25312^{53} - 1 (Number.MAX_SAFE_INTEGER), which is the largest number JavaScript can represent with a number primitive (or Number value).
  • Numbers: A primitive wrapper object used to represent and manipulate numbers and its type is a double-precision 64-bit binary format IEEE 754


Function PropertiesDescriptionReturn Type
asIntN(bits, bigint)clamp a BigInt value to a signed integer valuebigint
asUintN(bits, bigint)clamp a BigInt value to an unsigned integer valuebigint


Value PropertiesDescriptionNotationValue (Number)
EPSILONthe magnitude of the difference between 1 and the smallest value greater than 1, which is approximately 2522^{-52}ε\varepsilon2.220446049250313e-16
NaNthe value identicial to the global NaNNaNNaNNaN
MAX_SAFE_INTEGERthe maximum safe integer in JavaScript25312^{53}-19007199254740991
MAX_VALUEthe largest positive representable number2102412^{1024}-11.7976931348623157e+308
MIN_SAFE_INTEGERthe minimum safe integer in JavaScript (253+1-2^{53} + 1)253+1-2^{53}+1-9007199254740991
MIN_VALUEthe smallest positive representable number—that is, the positive number closest to zero (without actually being zero)210742^{-1074}5e-324
NEGATIVE_INFINITYnegative infinity-\infty-Infinity
POSITIVE_INFINITYthe value identicial to the global Infinity++\inftyInfinity (+Infinity)
Function PropertiesDescriptionReturn Type
isFinite(number)determine whether the passed value is a finite number or notboolean
isInteger(number)determine whether the passed value is an integer or notboolean
isNaN(number)determine whether the passed value is NaN or not (typeof number === 'number' && number !== number)boolean
isSafeInteger(number)determine whether the passed value is a safe integer (between 253+1-2^{53} + 1 and 25312^{53} - 1) or notboolean
parseFloat(string)the function identicial to the global parseFloatnumber (float)
parseInt(string, radix)the function identicial to the global parseIntnumber (integer)


  1. Number.isFinite(number) does not convert its argument to a Number before determining whether it is Infinity or not, which differs from the global isFinite(number) function. So Number.isNaN(number) does it as well.

Other Properties

  • Math: A a built-in object that has properties and methods for mathematical constants and functions. It’s not a function object. Math works with the Number type. It doesn't work with BigInt.


Value PropertiesDescriptionNotationValue (Number)
Ethe base of the natural logarithmsee2.7182818284590452354
LN10the natural logarithm of 10ln(10)\ln(10)2.302585092994046
LN2the natural logarithm of 2ln(2)\ln(2)0.6931471805599453
LOG10Ethe base-10 logarithm of eelog10(e)\log_{10}(e)0.4342944819032518
LOG2Ethe base-2 logarithm of eelog2(e)\log_{2}(e)1.4426950408889634
PIthe ratio of the circumference of a circle to its diameterπ\pi3.1415926535897932
SQRT1_2the square root of ½12\frac{1}{\sqrt{2}}0.7071067811865476
SQRT2the square root of 22\sqrt{2}1.4142135623730951
Function PropertiesDescriptionNotationReturn Type
abs(x)return the absolute value of xx\lvert x \rvert number
acos(x)return the inverse cosine of xarccos(x)\arccos(x)number
acosh(x)return the inverse hyperbolic cosine of xarcosh(x)\operatorname{arcosh}(x)number
asin(x)return the inverse sine of xarcsin(x)\arcsin(x)number
asinh(x)return the inverse hyperbolic sine of xarsinh(x)\operatorname{arsinh}(x)number
atan(x)return the inverse tangent of xarctan(x)\arctan(x)number
atanh(x)return the inverse hyperbolic tangent of xarctanh(x)\operatorname{arctanh}(x)number
atan2(y, x)return the inverse tangent of the quotient y / x of the arguments y and xarctan(yx)arctan(\frac{y}{x})number
cbrt(x)return the cube root of xx3\sqrt[3]{x}number
ceil(x)return the smallest integer greater than or equal to xx\lceil x \rceilnumber
clz32(x)return the number of leading zero bits of the 32-bit integer xnumber
cos(x)return the cosine of xcos(x)\cos(x)number
cosh(x)return the hyperbolic cosine of xex+ex2\frac{e^x + e^{-x}}{2}number
exp(x)return the exponential function of xexe^xnumber
expm1(x)return the result of subtracting 1 from the exponential function of xex1e^x - 1number
floor(x)return the largest integer less than or equal to xx\lfloor x \rfloornumber
fround(x)return the nearest single precision float representation of xnumber
hypot(...args)return the square root of the sum of squares of its arguments._i=1nxn2\sqrt{\sum\_{i=1}^{n}{x_n^2}}number
imul(x, y)return the result of the 32-bit integer multiplication of x and y.number
log(x)return the natural logarithm of xln(x)\ln(x)number
log1p(x)return the natural logarithm of 1 + xln(1+x)\ln(1+x)number
log10(x)return the base 10 logarithm of xlog10x\log_{10} xnumber
log2(x)return the base 2 logarithm of xlog2x\log_{2} xnumber
max(...args)return the largest of the resulting valuesmax{f(x1),...,f(xn)}\max \left \{ f\left ( x_1 \right ) ,...,f\left ( x_n \right ) \right \}number
min(...args)return the smallest of the resulting valuesmin{f(x1),...,f(xn)}\min \left \{ f\left ( x_1 \right ) ,...,f\left ( x_n \right ) \right \}number
pow(base, exponent)return base x to the exponent power y (that is, x^y)xyx^ynumber
random()return a pseudo-random number between 0 and 1x(0,1]x \in \left (0, 1 \right ]number
round(x)return the value of the number x rounded to the nearest integerx+12\lfloor x + \frac{1}{2} \rfloornumber
sign(x)return the sign of the x, indicating whether x is positive, negative, or zero±\pm number
sin(x)return the sine of xsinx\sin xnumber
sinh(x)return the hyperbolic sine of xexex2\frac{e^x - e^{-x}}{2}number
sqrt(x)return the positive square root of xx\sqrt{x}number
tan(x)return the tangent of xtan(x)\tan(x)number
tanh(x)return the hyperbolic tangent of xe2x1e2x+1\frac{e^{2x} - 1}{e^{2x}+1}number
trunc(x)return the integer portion of x, removing any fractional digitsnumber


  1. x ** y is recommended to implement x ^ y instead of Math.pow(x, y).
  2. ~~x is recommended to get the integer part of the given number instead of Math.trunc(x).