JavaScript - Math.log10() Method
The JavaScript Math.log10() method returns the base-10 logarithm of a given number.
Syntax
Math.log10(x)
Parameters
x |
Specify the number. |
Return Value
Returns the base-10 logarithm of a given number.
If the x is negative, it returns NaN.
If the x is 0, it returns -Infinity.
Example:
In the example below, Math.log10() method is used to calculate the base-10 logarithm of a given number.
var txt; txt = "Math.log10(1) = " + Math.log10(1) + "<br>"; txt = txt + "Math.log10(10) = " + Math.log10(10) + "<br>"; txt = txt + "Math.log10(50) = " + Math.log10(50) + "<br>"; txt = txt + "Math.log10(0) = " + Math.log10(0) + "<br>"; txt = txt + "Math.log10(-1) = " + Math.log10(-1) + "<br>";
The output (value of txt) after running above script will be:
Math.log10(1) = 0 Math.log10(10) = 1 Math.log10(50) = 1.6989700043360187 Math.log10(0) = -Infinity Math.log10(-1) = NaN
❮ JavaScript - Math Object