Favorites

JavaScript Math.log() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Math.log()
JavaScript Math Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

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

console.log(Math.log(1));
console.log(Math.log(Math.E));
console.log(Math.log(8) / Math.log(2));
console.log(Math.log(-1));

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee