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
Syntax
Math.log(x)
Parameters
| Parameter | Description |
|---|---|
x |
A number. |
Return value
A number; -Infinity for 0, NaN for negatives.
Examples
console.log(Math.log(Math.E), Math.log(1), Math.log(0));
Output
1 0 -Infinity
const logBase = (x, base) => Math.log(x) / Math.log(base);
console.log(logBase(81, 3).toFixed(10));
Output
4.0000000000
Version history
| Version | Change |
|---|---|
| JavaScript ES1 | Added |
Related
Math.log10()· Return the base-10 logarithm of a number, e.g. to count digits or work with decibels.Math.log2()· Return the base-2 logarithm of a number, e.g. how many bits or how many halvings are needed.Math.exp()· Return e (about 2.718) raised to the given power, used for exponential growth, decay and probability formulas.- JavaScript Math · tutorial
- JavaScript Numbers · tutorial