Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript
math
log
communitycreator

# What is Math.log1p() in JavaScript? Arslan Bajwa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Math is a built-in object in JavaScript that contains different methods and properties used to perform mathematical operations. It contains a log1p() function, which is used to compute the natural log of 1 plus the specified number.

## Syntax

Math.log1p(param);

## Parameter

• param: This is the input value of Number type, for which we want to find the log1p().

Number in JavaScript is a 64-bit double-precision value which is the same as double in C# or Java.

## Return value

• Number: It returns the natural log of ( 1 + param ). It is of the type Number.

• -Infinity: The function returns this if the input parameter param = -1.

• +Infinity: The function returns this if the input parameter param = +Infinity.

• NaN: The function returns this if the input parameter param < -1 or param = -Infinity.

The e in natural log is known as the Euler Number, and its value is equal to approximately 2.71828.

## Example

console.log("log1p(-2) = " + Math.log1p(-2));console.log("log1p(-1) = " + Math.log1p(-1));console.log("log1p(2) = " + Math.log1p(2));console.log("log1p(20) = " + Math.log1p(20));console.log("log1p(∞) = " + Math.log1p(Infinity));console.log("log1p(-∞) = " + Math.log1p(-Infinity));

RELATED TAGS

javascript
math
log
communitycreator

CONTRIBUTOR Arslan Bajwa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Learn in-demand tech skills in half the time 