totn JavaScript

JavaScript: Math exp() function

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

Description

In JavaScript, exp() is a function that is used to return e raised to the power of number (which is enumber). Because the exp() 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 exp() function is:

Math.exp(number);

Parameters or Arguments

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

Returns

The exp() function returns enumber 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 exp() is one of these functions.

Example

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

For example:

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

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

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

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

1
2.718281828459045
0.1353352832366127

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

The second output to the console log returned 2.718281828459045 which is the calculation of e1.

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