totn JavaScript

JavaScript: Math expm1() function

This JavaScript tutorial explains how to use the math function called expm1() with syntax and examples.

Description

In JavaScript, expm1() is a function that is used to return e raised to the power of number minus 1 (which is enumber - 1). Because the expm1() function is a static function of the Math object, it must be invoked through the placeholder object called Math.

Syntax

In JavaScript, the syntax for the expm1() function is:

Math.expm1(number);

Parameters or Arguments

number
The number used as the exponent in enumber - 1 where e is the base of natural logarithms.

Returns

The expm1() function returns enumber - 1 where e is the base of natural logarithms and number is the exponent used in the calculation. The mathematical constant e has an approximate value of 2.71828.

Note

  • Math is a placeholder object that contains mathematical functions and constants of which expm1() is one of these functions.

Example

Let's take a look at an example of how to use the expm1() function in JavaScript.

For example:

console.log(Math.expm1(0));
console.log(Math.expm1(1));
console.log(Math.expm1(-2));

In this example, we have invoked the expm1() function using the Math class.

We have written the output of the expm1() function to the web browser console log, for demonstration purposes, to show what the expm1() function returns.

The following will be output to the web browser console log:

0
1.718281828459045
-0.8646647167633873

In this example, the first output to the console log returned 1 which is the calculation of e0 - 1.

The second output to the console log returned 1.718281828459045 which is the calculation of e1 - 1.

The third output to the console log returned -0.8646647167633873 which is the calculation of e-2 - 1.