JavaScript Math.exp()
Syntax & Examples


Math.exp() static-method

The Math.exp() method in JavaScript returns e raised to the power of a given number (x), where e is Euler's number (approximately 2.718), the base of the natural logarithm. It is a static method of Math, meaning it is always used as Math.exp() and not as a method of a Math object created (Math is not a constructor).


Syntax of Math.exp()

The syntax of Math.exp() static-method is:

Math.exp(x)

This exp() static-method of Math returns e^x, where x is the argument, and e is Euler's number (2.718…, the base of the natural logarithm).

Parameters

ParameterOptional/RequiredDescription
xrequiredA number representing the exponent to raise e to.

Return Type

Math.exp() returns value of type Number.



✐ Examples

1 Using Math.exp() with a positive number

In this example, we use the Math.exp() method to calculate e raised to the power of 1.

For example,

  1. We call Math.exp() with 1 as the argument.
  2. The method returns e raised to the power of 1.
  3. We log the result to the console using console.log().

JavaScript Program

console.log(Math.exp(1));

Output

2.718281828459045

2 Using Math.exp() with zero

In this example, we use the Math.exp() method to calculate e raised to the power of 0.

For example,

  1. We call Math.exp() with 0 as the argument.
  2. The method returns e raised to the power of 0.
  3. We log the result to the console using console.log().

JavaScript Program

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

Output

1

3 Using Math.exp() with a negative number

In this example, we use the Math.exp() method to calculate e raised to the power of -1.

For example,

  1. We call Math.exp() with -1 as the argument.
  2. The method returns e raised to the power of -1.
  3. We log the result to the console using console.log().

JavaScript Program

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

Output

0.36787944117144233

Summary

In this JavaScript tutorial, we learned about exp() static-method of Math: the syntax and few working examples with output and detailed explanation for each example.