Math.log10()
Returns the base-10 logarithm of a number.
Syntax
Math.log10(x) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
x | number | Yes | The number whose base-10 logarithm is returned. |
Returns
number — log base 10 of x; NaN if x < 0.
Examples
console.log(Math.log10(1000));
Output
3
console.log(Math.log10(1), Math.log10(0));
Output
0 -Infinity
Notes
Useful for computing the number of digits or decibel scales. Returns NaN for
negative input and -Infinity for 0.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 38 |
| firefox | 25 |
| safari | 8 |
| edge | 12 |
| node | 0.12 |