JavaScript log() Method
Example
Return the natural logarithm of 2:
Math.log(2);
Output result:
0.6931471805599453
Try it »
Definition and Usage
The log() method returns the natural logarithm of a number (based on E).
**Note:** If x is negative, it returns NaN.
Note: If x is 0, it returns -Infinity .
Browser support





All major browsers support the log() method.
Syntax
Math.log(
x
)
Parameter value
| Parameters | Description |
|---|---|
| x | Required. Any numeric value or expression. |
Return Value
| Type | Description |
|---|---|
| Number | The natural logarithm of x. |
Technical Details
| JavaScript version: | 1.0 |
|---|
More examples
Example
In this example, we will apply log() to 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);
a,b,c,d, and LinkedHashMap, among others. e Output result:
1.0000066849139877
0.6931471805599453
0
-Infinity
NaN
Try it »
JavaScript Math object