JavaScript Math.log() Method
The Math.log() static method returns the natural logarithm (base e) of a number.
Description
The Math.log() static method returns the natural logarithm of a number, the power to which e must be raised to get it. Math.log(0) is -Infinity and negative numbers give NaN. For other bases, use Math.log10(), Math.log2() or Math.log(x) / Math.log(base).
Logarithms are useful for scales that grow exponentially, such as volume, sound levels and some chart axes, and for working out how many steps a doubling or halving process takes. Math.log1p(x) gives ln(1 + x) more accurately for very small values of x.
Like every member of Math, it's called on the Math object itself rather than on a number, and it only works with the Number type: passing a BigInt throws a TypeError.
Syntax
Math.log(x)Parameters
- xA number, 0 or greater.
Return Value
The natural logarithm (base e) of x; NaN for negative numbers.
Example
Browser Support
The following information will show you the current browser support for the Math.log() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





