JavaScript Math.log10()

The Math.log10() method returns the base 10 logarithm of a number. It is equivalent to log10(x) in mathematics.

Example


log10() Syntax

The syntax of log10() is:

Math.log10(x)

Here, log10() is a static method. Hence, we need to access the method using the class name, Math.


log10() Parameter

The log10() method takes in:

  • x - a number

log10() Return Values

The log10() method returns:

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

Example 1: JavaScript Math.log10()

Output

0
1

In the above example,

  • Math.log10(1) - computes the base 10 log value of 1
  • Math.log10(10) - computes the base 10 log value of 10

Example 2: log10() With 0

In the above example, we have used the log10() method to compute the base 10 log value of 0.

The output -Infinity indicates that the base 10 log value of 0 is negative infinity.


Example 3: log10() With Negative Values

In the above example, we have used the log10() method to compute the base 10 log value of a negative number.

The output NaN stands for Not a Number. We get this result because the base 10 log value of negative numbers is undefined.


Recommended Readings: