exponential

Math.log

Returns the natural logarithm (base e, or ln) of a number. Inverse of Math.exp.

Math.log(x)

Parameters & edge cases

Case Behavior
x A positive number; must be > 0 for a real result
log(0) Math.log(0) returns -Infinity
log(negative) Math.log(-1) returns NaN — no complex logs in JS

Examples

console.log(Math.log(1));      // 0

ln(1) = 0 for any base.

console.log(Math.log(Math.E)); // 1

ln(e) = 1 — the defining property of the natural log.

console.log(Math.log(0));      // -Infinity

Log of zero is negative infinity.

console.log(Math.log(-1));     // NaN

Negative inputs return NaN.

Gotcha

Math.log is base-e, NOT base-10. Use Math.log10 or Math.log2 for common bases, or (Math.log(x) / Math.log(base)) for arbitrary bases.

Related

← All JS Math methods · Array methods