Exponentiation & Logarithmic Methods
These methods handle powers, roots, and logarithms.
pow(base, exponent)
Returns base
raised to the power of exponent
.
Example:
console.log(Math.pow(2, 3)); // 8
sqrt(x)
Returns the square root of x
. Returns NaN
if x < 0
.
Example:
console.log(Math.sqrt(16)); // 4
cbrt(x)
Returns the cube root of x
.
Example:
console.log(Math.cbrt(8)); // 2
exp(x)
Returns Math.E
raised to the power of x
.
Example:
console.log(Math.exp(1)); // 2.718281828459045
expm1(x)
Returns Math.exp(x) - 1
, optimized for small x
.
Example:
console.log(Math.expm1(0.0001)); // 0.000100005
log(x)
Returns the natural logarithm (base Math.E
) of x
. Returns NaN
if x <= 0
.
Example:
console.log(Math.log(Math.E)); // 1
log1p(x)
Returns the natural logarithm of 1 + x
, optimized for small x
.
Example:
console.log(Math.log1p(0.0001)); // 0.000099995
log10(x)
Returns the base-10 logarithm of x
.
Example:
console.log(Math.log10(100)); // 2
log2(x)
Returns the base-2 logarithm of x
.
Example:
console.log(Math.log2(8)); // 3
Example usage (growth calculation):
let initial = 1000, rate = 0.05, years = 2;
console.log(initial * Math.exp(rate * years)); // 1105.1709180756477