Math.log()

Returns the natural logarithm (base e) of a number.

Since ES1 Spec ↗

Syntax

Math.log(x)

Parameters

NameTypeRequiredDescription
x number Yes The number whose natural logarithm is returned.

Returns

number — ln(x); NaN if x < 0, -Infinity if x is 0.

Examples

console.log(Math.log(Math.E));
Output
1
console.log(Math.log(1), Math.log(0));
Output
0 -Infinity

Notes

This is the natural log (base e), not base 10 - use `Math.log10` for that. Returns NaN for negative input and -Infinity for 0.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also