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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Math.log10(x)

Parameters

ParameterDescription
x A number.

Return value

A number.

Examples

Powers of tenTry it yourself
console.log(Math.log10(1000), Math.log10(0.01));

Output

3 -2
Count the digits of a positive integerTry it yourself
const digits = (n) => Math.floor(Math.log10(n)) + 1;
console.log(digits(7), digits(12345));

Output

1 5

Version history

VersionChange
JavaScript ES2015Added

Was this page helpful?