JavaScript (ES2026) reference · Math Methods and Constants
JavaScript Math.log10() Method
Return the base-10 logarithm of a number, e.g. to count digits or work with decibels.
JavaScript (ES2026) Since ES2015
Syntax
Math.log10(x)
Parameters
| Parameter | Description |
|---|---|
x |
A number. |
Return value
A number.
Examples
console.log(Math.log10(1000), Math.log10(0.01));
Output
3 -2
const digits = (n) => Math.floor(Math.log10(n)) + 1;
console.log(digits(7), digits(12345));
Output
1 5
Version history
| Version | Change |
|---|---|
| JavaScript ES2015 | Added |
Related
Math.log()· Return the natural logarithm (base e) of a number; divide by Math.log(base) to get a logarithm in any base.Math.log2()· Return the base-2 logarithm of a number, e.g. how many bits or how many halvings are needed.- JavaScript Math · tutorial
- JavaScript Numbers · tutorial