# Introduction JavaScript exp() Function with Examples

In JavaScript, exp() is a function that is used to return e raised to the power of number (which is enumber). Because the exp() function is a static function of the Math object, it must be invoked through the placeholder object called Math.

### Syntax

``````Math.exp(x)

``````

### Parameter(s)

• `x` − A numbers.

### Return value

Returns the exponential value of the variable x.

Note

• For a positive argument x, Math.log(Math.exp(x)) gives value x.
• If the argument is negative infinity, then this method returns 0.
• If the argument is positive infinity, then this method returns positive infinity.
• If an argument is positive zero or negative zero, then this method returns 1.
• If the passed value is not a valid number, the method returns NaN.
• If the passed value is null, the method returns 1.

## Browser Support:

• Internet Explorer v3
• Firefox v1
• Edge v12
• Opera
• Safari v1
• Android webview v1
• Chrome for Android v18
• Firefox for Android v4
• Opera for Android
• Safari on iOS v1
• Samsung Internet v1.0
• Node.js

## JavaScript exp() Method with Example

### Example 1

``````
console.log(Math.exp(0));
console.log(Math.exp(1));
console.log(Math.exp(-2));

``````

In this example, we have invoked the exp() function using the Math class.

We have written the output of the exp() function to the web browser console log, for demonstration purposes, to show what the exp() function returns.

Output

``````
1
2.718281828459045
0.1353352832366127

``````

In this example, the first output to the console log returned 1 which is the calculation of e0.

The second output to the console log returned 2.718281828459045 which is the calculation of e1.

The third output to the console log returned 0.1353352832366127 which is the calculation of e-2.

### Example 2

The following example demonstrates that if the passed value is not a valid number, then the method returns NaN.

``````
var a = "JavaScript";
var b;

console.log(Math.exp(a));
console.log(Math.exp(b));

``````

Output

``````
NaN
NaN

``````

### Example 3

The following example demonstrates the case of the parameter as infinity(positive/negative) and zero(positive/negative).

For example:

``````
var a = Number.POSITIVE_INFINITY;
var b = Number.NEGATIVE_INFINITY;

var c = 0;
var d = -0;

console.log(Math.exp(a));
console.log(Math.exp(b));
console.log(Math.exp(c));
console.log(Math.exp(d));

``````

Output

``````
Infinity
0
1
1

``````

### Example 4

The following example demonstrates that if null is passed as an argument, then this method returns 1.

``````
var a = null;
var b = "";
var c = [];

console.log(Math.exp(a));
console.log(Math.exp(b));
console.log(Math.exp(c));

``````

Output

``````
1
1
1

``````

### Example 5

The Javascript exp() method cannot be used with complex arguments as only integer arguments are accepted.

``````
//Complex values cannot be passed as arguments as follows
//since only integer arguments are accepted.

console.log(Math.exp(2+i));

``````

Output

``````
ReferenceError: i is not defined

``````