JavaScript Math.log10()
Syntax & Examples


Math.log10() static-method

The Math.log10() method in JavaScript returns the base-10 logarithm of a number. This logarithm is the power to which the number 10 must be raised to obtain the value of the input number. It is a static method of Math, meaning it is always used as Math.log10() and not as a method of a Math object created (Math is not a constructor).


Syntax of Math.log10()

The syntax of Math.log10() static-method is:

Math.log10(x)

This log10() static-method of Math returns the base-10 logarithm of x.

Parameters

ParameterOptional/RequiredDescription
xrequiredA number for which to return the base-10 logarithm.

Return Type

Math.log10() returns value of type Number.



✐ Examples

1 Using Math.log10() with a positive number

In this example, we use the Math.log10() method to find the base-10 logarithm of 100.

For example,

  1. We call Math.log10() with 100 as the argument.
  2. The method returns the base-10 logarithm of 100.
  3. We log the result to the console using console.log().

JavaScript Program

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

Output

2

2 Using Math.log10() with 1

In this example, we use the Math.log10() method to find the base-10 logarithm of 1.

For example,

  1. We call Math.log10() with 1 as the argument.
  2. The method returns the base-10 logarithm of 1, which is 0.
  3. We log the result to the console using console.log().

JavaScript Program

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

Output

0

3 Using Math.log10() with a number less than 1

In this example, we use the Math.log10() method to find the base-10 logarithm of 0.01.

For example,

  1. We call Math.log10() with 0.01 as the argument.
  2. The method returns the base-10 logarithm of 0.01.
  3. We log the result to the console using console.log().

JavaScript Program

console.log(Math.log10(0.01));

Output

-2

Summary

In this JavaScript tutorial, we learned about log10() static-method of Math: the syntax and few working examples with output and detailed explanation for each example.