The exp method in JavaScript's Math object returns the exponential value of a specified number, represented as e raised to the power of x. In this case, x serves as the input parameter, while e denotes the base of natural logarithms.
Syntax
The syntax for the exp method is illustrated as follows:
Example
Math.exp(num)
Parameter
num - A number.
Return
The number in the form of e x .
JavaScript Math exp method example
In this section, we will explore the exp function by examining different examples and scenarios.
Example 1
Let’s examine an example that demonstrates how to output a specified value in the format of e raised to the power of x.
Example
<script>
document.writeln(Math.exp(1)+"<br>");
document.writeln(Math.exp(5)+"<br>");
document.writeln(Math.exp(-5));
</script>
Output:
Output
2.718281828459045
148.4131591025766
0.006737946999085467
Example 2
In this section, you have the opportunity to evaluate the exp method using your personalized test cases.
Example
<script>
function display()
{
var x=document.getElementById("num").value;
document.getElementById("result").innerHTML=Math.exp(x);
}
</script>
<form>
Enter a number: <input type="text" id="num">
<input type="button" onclick="display()" value="submit">
</form>
<p><span id="result"></span></p>