
The JavaScript Math.exp() returns the value of Ex, where E is Euler’s number (approx. 2.7183) and x is the number passed to it.
Syntax:
Math.exp(number)
Example:
<!DOCTYPE html>
<html>
<body>
<button onclick="expFunction()">Try it</button>
<p id="example"></p>
<script>
function expFunction() {
document.getElementById("example").innerHTML = Math.exp(2);
}
</script>
</body>
</html>
Output:
Click the button to display the result of Math.exp(2):
The JavaScript Math.expm1() returns the value of Ex minus 1, where E is Euler’s number (approx. 2.7183) and x is the number passed to it.
Note: The JavaScript Math.expm1() is more precise than, Math.exp() and subtracting 1.
Syntax:
Math.expm1(x)
Example:
<!DOCTYPE html>
<html>
<body>
<button onclick="expm1Function()">Try it</button>
<p id="example1"></p>
<script>
function expm1Function() {
document.getElementById("example1").innerHTML = Math.expm1(2);
}
</script>
</body>
</html>
Output:
Click the button to display the result of Math.expm1(2).
Enjoy coding!
Read also: