JavaScript Math.log10() Method
The Math.log10() static method returns the base-10 logarithm of a number.
Description
The Math.log10() static method returns the base-10 logarithm of a number. Math.floor(Math.log10(n)) + 1 is a quick way to count the digits of a positive integer.
It returns -Infinity for 0 and NaN for negative numbers. Base-10 logarithms are used for orders of magnitude, decibel calculations and logarithmic chart scales.
The digit-counting trick only works for positive integers; for 0, negative numbers and decimals, converting to a string, as in String(Math.abs(Math.trunc(n))).length, is simpler and handles every case. Like every member of Math, it's called on the Math object itself rather than on a number, and it only works with the Number type: passing a BigInt throws a TypeError.
Syntax
Math.log10(x)Parameters
- xA number.
Return Value
The base-10 logarithm of x.
Example
Browser Support
The following information will show you the current browser support for the Math.log10() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





