JS: Math exponential and logarithm
exponential function
Math.exp(x)-
e raised to the power of x.
exponential P2Yc6 ll console.log(Math.exp(1)); // 2.718281828459045 console.log(Math.exp(1) === Math.E); // true console.log(Math.exp(2)); // 7.38905609893065 Math.expm1(x)-
(new in ECMAScript 2015)
Same as
Math.exp(x) -1but the result is computed in a way that is accurate even when the value of x is close 0.console.log(Math.expm1(1) === (Math.exp(1) - 1)); // true console.log(Math.expm1(2) === (Math.exp(2) - 1)); // true console.log(Math.expm1(0) === (Math.exp(0) - 1)); // true // s------------------------------ console.log(Math.expm1(0.1) === (Math.exp(0.1) - 1)); // false console.log(Math.expm1(0.1)); // 0.10517091807564763 console.log(Math.exp(0.1) - 1); // 0.10517091807564771
Natural log
Math.log(x)-
Natural log of x
natural log 2026-07-07 2a7b4 ll console.log(Math.log(Math.E)); // 1 console.log(Math.E); // 2.718281828459045 console.log(Math.log(2.718281828459045)); // 1 console.log(Math.log(2)); // 0.6931471805599453
Math.log1p(x)-
(new in ECMAScript 2015)
Natural log of
(x+1)console.log(Math.log1p(1) === Math.log(1 + 1)); // true console.log(Math.log1p(2) === Math.log(2 + 1)); // true console.log(Math.log1p(3) === Math.log(3 + 1)); // true console.log(Math.log1p(Math.E) === Math.log(Math.E + 1)); // true // s------------------------------ console.log(Math.log1p(0.1) === (Math.log(0.1 + 1))); // false console.log(Math.log1p(0.1)); // 0.09531017980432487 console.log(Math.log(0.1 + 1)); // 0.09531017980432493
Math.log10(x)-
(new in ECMAScript 2015)
Base 10 log of x
log base 10 ZQPhr ll console.log(Math.log10(100)); // 2 console.log(Math.log10(1000)); // 3 console.log(Math.log10(10000)); // 4 Math.log2(x)-
(new in ECMAScript 2015)
Base 2 log of x
log base 2 jJY2d ll console.log(Math.log2(2)); // 1 console.log(Math.log2(4)); // 2 console.log(Math.log2(8)); // 3 console.log(Math.log2(16)); // 4
JavaScript. math functions.
- JS: Math (namespace)
- JS: Math. max, min
- JS: Math. sign, abs
- JS: Math ceiling, floor, round, truncate
- JS: Math. random
- JS: Power and Roots
- JS: Math exponential and logarithm
- JS: Math constants. pi, e, sqrt, etc.
- JS: Math trig functions. sin, cos, tan, asin, acos, atan
- JS: Math hyperbolic functions. sinh, cosh, tanh, etc.
- JS: Math fround, clz32, imul