JavaScript Math.log()
Syntax & Examples


Math.log() static-method

The Math.log() method in JavaScript returns the natural logarithm (㏒e, also known as ㏑) of a number. The natural logarithm is the logarithm to the base e (approximately 2.718). It is a static method of Math, meaning it is always used as Math.log() and not as a method of a Math object created (Math is not a constructor).


Syntax of Math.log()

The syntax of Math.log() static-method is:

Math.log(x)

This log() static-method of Math returns the natural logarithm (㏒e; also, ㏑) of x.

Parameters

ParameterOptional/RequiredDescription
xrequiredA number for which to return the natural logarithm.

Return Type

Math.log() returns value of type Number.



✐ Examples

1 Using Math.log() with a positive number

In this example, we use the Math.log() method to find the natural logarithm of 10.

For example,

  1. We call Math.log() with 10 as the argument.
  2. The method returns the natural logarithm of 10.
  3. We log the result to the console using console.log().

JavaScript Program

console.log(Math.log(10));

Output

2.302585092994046

2 Using Math.log() with 1

In this example, we use the Math.log() method to find the natural logarithm of 1.

For example,

  1. We call Math.log() with 1 as the argument.
  2. The method returns the natural logarithm of 1, which is 0.
  3. We log the result to the console using console.log().

JavaScript Program

console.log(Math.log(1));

Output

0

3 Using Math.log() with a number less than 1

In this example, we use the Math.log() method to find the natural logarithm of 0.5.

For example,

  1. We call Math.log() with 0.5 as the argument.
  2. The method returns the natural logarithm of 0.5.
  3. We log the result to the console using console.log().

JavaScript Program

console.log(Math.log(0.5));

Output

-0.6931471805599453

Summary

In this JavaScript tutorial, we learned about log() static-method of Math: the syntax and few working examples with output and detailed explanation for each example.