JavaScript Math log() method

18 Mar 2025 | 1 min read

The JavaScript math log() method returns the natural logarithm of the given number i.e. base e. If the number is negative, it returns NaN.

Syntax

The log() method is represented by the following syntax:

Parameter

num - A number.

Return

The natural logarithm of a number.

JavaScript Math log() method example

Here, we will understand log() method through various examples.

Example 1

Let's see an example to print the natural logarithm of a number.

Output:

 0 1.6094379124341003 2.302585092994046 

Example 2

Let's see the result of log() method in different test cases.

Output:

 NaN NaN -Infinity 

Example 3

Here, you can test log() method with your own test cases.

 
Next TopicJavaScript Math