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

Result