Javascript - Math log() Method

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

Description

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.

Syntax

Math.log(x)

Parameter Values

Parameter RequireDescription
x Required. A number

Return

A Number, representing the natural logarithm of a specified number

Example

Return the natural logarithm of the number "2":

Demo

//display the natural logarithm of a number.
console.log(Math.log(2));// ww  w  . j  a  v a 2  s  . c om

//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);

Result