JavaScript Math exp() method - JavaScript Tutorial

JavaScript Math exp() method

BLUF: This tutorial on JavaScript Math exp() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Math exp() method

Understanding JavaScript Math exp() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

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>

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience