JavaScript log() Method

Definition and Usage

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

Note:If the parameter x If the parameter is negative, it returns NaN.

Note:If the parameter x If the parameter is 0, it returns -Infinity.

Example

Example 1

Returns the natural logarithm of the number "2":

Math.log(2);

Try It Yourself

Example 2

Use the log() method for 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);

Try It Yourself

Syntax

Math.log(x)

Parameter Value

Parameter Description
x Required. Any number or expression. Must be greater than 0.

Technical Details

Return Value: A number representing the natural logarithm of the specified number.
JavaScript Version: ECMAScript 1

Browser Support

Method Chrome Edge Firefox Safari Opera
log() Support Support Support Support Support

Related Pages

Tutorial:JavaScript Math