JavaScript Math exp() Method
Last Updated :
18 Apr, 2023
JavaScript Math.exp() is used to get the value of ep, where p is any given number. The number e is a mathematical constant having an approximate value equal to 2.718. It was discovered by the Swiss mathematician Jacob Bernoulli. 2.718 is also called Euler’s number.
Syntax:
Math.exp(p)
Parameter: This method accepts a single parameter
Return Value: It returns the value of ep, where p is any given number as a parameter.
Example:
Input : Math.exp(0)
Output : 1
Explanation: Here the value of parameter p is 0, So after putting the value 0 instead of p in ep then its value becomes 1.
Input : Math.exp(2)
Output : 7.38905609893065
Explanation: Here the value of parameter p is 2, So after putting the value 2 instead of p in ep then its value becomes 7.38905609893065.
Below example illustrate the JavaScript Math exp() Method:
Example 1:
Javascript
console.log(Math.exp(0));
console.log(Math.exp(1));
console.log(Math.exp(2));
console.log(Math.exp(-1));
console.log(Math.exp(-7));
console.log(Math.exp(10));
console.log(Math.exp(1.2));
|
Output
1
2.718281828459045
7.38905609893065
0.36787944117144233
0.0009118819655545162
22026.465794806718
3.3201169227365472
Example 2: Here parameter should be a number otherwise it gives an error or NaN i.e, not a number.
Javascript
<script>
console.log(Math.exp(a));
</script>
|
Output:
Error: a is not defined
Javascript
console.log(Math.exp( "gfg" ));
|
Example -3 : If we don’t pass any parameter to the method then it will also return NaN.
Supported Browsers: The browsers supported by JavaScript Math.E() function are listed below:
- Google Chrome 1 and above
- Internet Explorer 3 and above
- Edge 12 and above
- Firefox 1 and above
- Opera 3 and above
- Safari 1 and above
We have a complete list of Javascript Math Objects methods, to check those please go through this Javascript Math Object Complete reference article.
Share your thoughts in the comments
Please Login to comment...