The log() method returns the natural logarithm (base E) of a number.
The log() method returns the natural logarithm (base E) of a number.
If the parameter x is negative, NaN is returned.
If the parameter x is 0, -Infinity is returned.
Math.log(x)
Parameter | Require | Description |
---|---|---|
x | Required. | A number |
A Number, representing the natural logarithm of a specified number
Return the natural logarithm of the number "2":
//display the natural logarithm of a number. console.log(Math.log(2));/*from ww w . j a v a2 s . c o m*/ //Use the log() method on different numbers: //display the natural logarithm of different numbers. var a = Math.log(2.7183); var b = Math.log(2); var c = Math.log(1); var d = Math.log(0); var e = Math.log(-1); var x = a + "\n" + b + "\n" + c + "\n" + d + "\n" + e; console.log(x);