Math.E() is an inbuilt function in JavaScript which 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.
- This number is also called Euler’s number.
Syntax:
Math.exp(p)
Paramter:
- Here p is the parameter and it is any number.
- It return the value of ep, where p is any given number as parameter.
Return Value:
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.
Let’s see JavaScript program:
// Here different values is being taken as // as parameter of Math.exp() function. 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
Error Or Exceptions associated:
Here parameter should must be a number otherwise it give error or NaN i.e, not a number.
Code #1:
// Here alphabet parameter give error. console.log(Math.exp(a)); |
Output:
Error: a is not defined
Code #2:
// Here parameter as a string give NaN. console.log(Math.exp( "gfg" )); |
Output:
> NaN
leave a comment
0 Comments