Favorites

JavaScript Math.log10() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Math.log10()
JavaScript Math Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

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

console.log(Math.log10(1000));
console.log(Math.log10(0.01));
const n = 45678;
console.log('Digits:', Math.floor(Math.log10(n)) + 1);

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee