The Math.exp() method returns e (Euler's constant) raised to the given power. It is equivalent to ex in mathematics.
Example
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).
NaNfor non-numeric arguments.
Example 1: JavaScript Math.exp()
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.e1Math.exp(2)- computes e (Euler's constant) raised to the power of 2 i.e.e2Math.exp(5)- computes e (Euler's constant) raised to the power of 5 i.e.e5
Example 2: exp() With 0
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
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.
Recommended Readings: