exponential

Math.log10

Returns the base-10 logarithm of a number. Introduced in ES2015 for accurate common-log calculations (decibels, pH, orders of magnitude).

Math.log10(x)

Parameters & edge cases

Case Behavior
x A positive number
digit count Math.floor(Math.log10(n)) + 1 gives the number of decimal digits in a positive integer
ES2015+ Polyfill: Math.log(x) / Math.LN10

Examples

console.log(Math.log10(1000)); // 3

10³ = 1000.

console.log(Math.log10(1));    // 0

log₁₀(1) = 0.

console.log(Math.log10(100));  // 2

10² = 100.

console.log(Math.log10(0.1));  // -1

10⁻¹ = 0.1.

Gotcha

Math.log10(1000) === 3 in most engines but rounding errors can produce 2.9999999999999996 for other inputs — always round before using as an integer index.

Related

← All JS Math methods · Array methods