JavaScript log()Method

Math 对象参考手册JavaScript Math Object

Example

Return the natural logarithm of 2:

Math.log(2);

Output:

0.6931471805599453

Try it Yourself »

Definition and Usage

The log() method returns the natural logarithm of a number (based on E).

Note:If x is negative, it returnsNaN。

Note:If x is 0, it returns-Infinity 。


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the log() method


Syntax

Math.log(x)

Parameter Values

Parameter 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, andeOutput:

1.0000066849139877
0.6931471805599453
0
-Infinity
NaN

Try it Yourself »


Math 对象参考手册JavaScript Math Object

Other Extensions