Visitar URL original
JavaScript Math.exp() Method
Selected Reading

JavaScript Math.exp() Method



The Math.exp() method in JavaScript is used to return the result of raising Euler's number (approximately equal to 2.718) to the power of a specified number. It calculates the exponential value of the provided number, where Euler's number raised to the power of x is denoted as e^x.

The formula for calculating Euler's number raised to the power of x −

Math.exp(x) = e^x

where "e" is Euler's number and "x" is the number for which the exponential value is to be calculated.

Syntax

Following is the syntax of JavaScript Math.exp() method −

Math.exp(x)

Parameters

This method accepts only one parameter. The same is described below −

  • x: A numeric value.

Return value

This method returns the value of e raised to the power of x.

Example 1

In the following example, we are using the JavaScript Math.exp() method to calculate "e" raised to the power of 2.

<html>
<body>
<script>
   const result = Math.exp(2);
   document.write(result);
</script>
</body>
</html>

Output

If we execute the above program, it returns "7.3890" as result.

Example 2

In this example, we are computing "e" raised to the power of -1 −

<html>
<body>
<script>
   const result = Math.exp(-1);
   document.write(result);
</script>
</body>
</html>

Output

If we execute the above program, it will return 0.3678 as result.

Example 3

In this example, we are calculating e raised to the power of 0 −

<html>
<body>
<script>
   const result = Math.exp(0);
   document.write(result);
</script>
</body>
</html>

Output

The result will be 1, as any number raised to the power of 0 is 1.

Example 4

Here, we are passing "Infinity" and "-Infinity" as arguments to this method −

<html>
<body>
<script>
   const result1 = Math.exp(Infinity);
   const result2 = Math.exp(-Infinity);
   document.write(result1, <br>, result2);
</script>
</body>
</html>

Output

If we execute the above program, it returns Infinity and 0 as result, respectively.

Advertisements