JavaScript Math.log1p()

Posted by

Method

JavaScript Math.log1p() Method

The JavaScript Math.log1p() method is used to calculate
the natural logarithm of a number plus one. It is equivalent to the
natural logarithm of the number (ln) plus one. It returns the natural
logarithm of (number + 1).

Syntax

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

Math.log1p(number)

[/dm_code_snippet]

The syntax for the Math.log1p() method is given above.

The number parameter is required. It is the number whose logarithm of
one plus needs to be calculated.

Return Value

The Math.log1p() method returns the natural logarithm of the specified
number plus one.

Browser Support

The Math.log1p() method is supported in all major browsers.

Examples

Let’s look at some examples of using the Math.log1p() method.

The following example logs the natural logarithm of 4 plus one:

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

console.log(Math.log1p(4));

// Output: 1.3862943611198906

[/dm_code_snippet]

The following example logs the natural logarithm of 0 plus one:

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

console.log(Math.log1p(0));

// Output: 0

[/dm_code_snippet]

Conclusion

The Math.log1p() method is used to calculate the natural logarithm of
a number plus one. It is equivalent to the natural logarithm of the
number (ln) plus one. It returns the natural logarithm of (number +
1).