JavaScript Math.expm1()
Syntax & Examples
Math.expm1() static-method
The Math.expm1() method in JavaScript returns e raised to the power of a given number (x), minus 1. This is equivalent to Math.exp(x) - 1, where e is Euler's number (approximately 2.718). It is a static method of Math, meaning it is always used as Math.expm1() and not as a method of a Math object created (Math is not a constructor).
Syntax of Math.expm1()
The syntax of Math.expm1() static-method is:
Math.expm1(x)
This expm1() static-method of Math returns e^x - 1, where x is the argument, and e is Euler's number (2.718…, the base of the natural logarithm).
Parameters
Parameter | Optional/Required | Description |
---|---|---|
x | required | A number representing the exponent to raise e to, before subtracting 1. |
Return Type
Math.expm1() returns value of type Number
.
✐ Examples
1 Using Math.expm1() with a positive number
In this example, we use the Math.expm1()
method to calculate e raised to the power of 1, minus 1.
For example,
- We call
Math.expm1()
with 1 as the argument. - The method returns e raised to the power of 1, minus 1.
- We log the result to the console using
console.log()
.
JavaScript Program
console.log(Math.expm1(1));
Output
1.718281828459045
2 Using Math.expm1() with zero
In this example, we use the Math.expm1()
method to calculate e raised to the power of 0, minus 1.
For example,
- We call
Math.expm1()
with 0 as the argument. - The method returns e raised to the power of 0, minus 1.
- We log the result to the console using
console.log()
.
JavaScript Program
console.log(Math.expm1(0));
Output
0
3 Using Math.expm1() with a negative number
In this example, we use the Math.expm1()
method to calculate e raised to the power of -1, minus 1.
For example,
- We call
Math.expm1()
with -1 as the argument. - The method returns e raised to the power of -1, minus 1.
- We log the result to the console using
console.log()
.
JavaScript Program
console.log(Math.expm1(-1));
Output
-0.6321205588285577
Summary
In this JavaScript tutorial, we learned about expm1() static-method of Math: the syntax and few working examples with output and detailed explanation for each example.