JavaScript - Math.log() Method
The JavaScript Math.log() method returns the natural logarithm (base-e) of a given number.
Syntax
Math.log(x)
Parameters
x |
Specify the number. |
Return Value
Returns the natural logarithm (base-e) 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.log() method is used to calculate the natural logarithm (base-e) of a given number.
var txt; txt = "Math.log(1) = " + Math.log(1) + "<br>"; txt = txt + "Math.log(Math.E) = " + Math.log(Math.E) + "<br>"; txt = txt + "Math.log(50) = " + Math.log(50) + "<br>"; txt = txt + "Math.log(0) = " + Math.log(0) + "<br>"; txt = txt + "Math.log(-1) = " + Math.log(-1) + "<br>";
The output (value of txt) after running above script will be:
Math.log(1) = 0 Math.log(Math.E) = 1 Math.log(50) = 3.912023005428146 Math.log(0) = -Infinity Math.log(-1) = NaN
❮ JavaScript - Math Object