JavaScript Math.exp()

The Math.exp() method returns e (Euler's constant) raised to the given power. It is equivalent to ex in mathematics.

Example

// calculate e (Euler's constant) power to 2 var value = Math.exp(2);
console.log(value); //Output: 7.38905609893065

exp() Syntax

The syntax of the exp() method is:

Math.exp(x)

Here, exp() is a static method. Hence, we need to access the method using the class name, Math.


exp() Parameters

The exp() method takes in:

  • x - a number

exp() Return Value

The exp() method returns:

  • ex for argument x, where e is Euler's constant (2.71828).
  • NaN for non-numeric arguments.

Example 1: JavaScript Math.exp()

// calculate e raised to the power of 1 var value1 = Math.exp(1);
console.log(value1);
// calculate e raised to the power of 2 var value2 = Math.exp(2);
console.log(value2);
// calculate e raised to the power of 5 var value3 = Math.exp(5);
console.log(value3);

Output

2.718281828459045
7.38905609893065
148.4131591025766

In the above example,

  • Math.exp(1) - computes e (Euler's constant) raised to the power of 1 i.e. e1
  • Math.exp(2) - computes e (Euler's constant) raised to the power of 2 i.e. e2
  • Math.exp(5) - computes e (Euler's constant) raised to the power of 5 i.e. e5

Example 2: exp() With 0

// calculate e raised to the power of 0 var value = Math.exp(0);
console.log(value); // Output: 1

In the above example, we have used the exp() method to compute e (Euler's constant) raised to the power of 0 i.e. e0.

The output 1 indicates that e raised to the power 0 is 1 i.e. e0 = 1.


Example 3: exp() With Negative Numbers

// calculate e raised to -1 var value = Math.exp(-1);
console.log(value); // Output: 0.36787944117144233

In the above example, we have used the exp() method to compute e (Euler's constant) raised to the power of -1 i.e. e-1.

The output indicates that e-1 is a positive number 0.36787944117144233.


Also Read:

Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges