Math.log()
Returns the natural logarithm (base e) of a number.
Syntax
Math.log(x) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
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
| Environment | Since version |
|---|---|
| chrome | 1.0 |
| firefox | 1.0 |
| safari | 1.0 |
| edge | 12 |
| node | 0.10 |