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
Parameter | Optional/Required | Description |
---|---|---|
x | required | A 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,
- We call
Math.log10()
with 100 as the argument. - The method returns the base-10 logarithm of 100.
- 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,
- We call
Math.log10()
with 1 as the argument. - The method returns the base-10 logarithm of 1, which is 0.
- 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,
- We call
Math.log10()
with 0.01 as the argument. - The method returns the base-10 logarithm of 0.01.
- 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.