JavaScript (ES2026) reference · Math Methods and Constants

JavaScript Math.log() Method

Return the natural logarithm (base e) of a number; divide by Math.log(base) to get a logarithm in any base.

JavaScript (ES2026) Since ES1

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Math.log(x)

Parameters

ParameterDescription
x A number.

Return value

A number; -Infinity for 0, NaN for negatives.

Examples

Natural logarithmTry it yourself
console.log(Math.log(Math.E), Math.log(1), Math.log(0));

Output

1 0 -Infinity
Logarithm in any baseTry it yourself
const logBase = (x, base) => Math.log(x) / Math.log(base);
console.log(logBase(81, 3).toFixed(10));

Output

4.0000000000

Version history

VersionChange
JavaScript ES1Added

Was this page helpful?