JavaScript Math log10()

The JavaScript Math.log10() function returns the base 10 logarithm of a number.

It is equivalent to log10(x) in mathematics.

The syntax of the Math.log10() function is:

Math.log10(x)

log10(), being a static method, is called using the Math class name.


Math.log10() Parameters

The Math.log10() function takes in:

  • x - A number

Return value from Math.log10()

  • Returns the base 10 logarithm of the given number.
  • Returns NaN for negative numbers and non-numeric arguments.

Example: Using Math.log10()

// Using Math.log10()
var value = Math.log10(1);
console.log(value); // 0

var value = Math.log10(10000);
console.log(value); // 4

var value = Math.log10("10");
console.log(value); // 1

var value = Math.log10(0);
console.log(value); // -Infinity

var value = Math.log10(-1);
console.log(value); // NaN

Output

0
4
1
-Infinity
NaN

Notes:

  • Use the constant Math.LOG10E for log10(e).
  • Use the functions Math.log() or Math.log2() for logarithm base e and 2.

Recommended readings: