File size: 2,303 Bytes
780c9fe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
---
title: Math.exp()
short-title: exp()
slug: Web/JavaScript/Reference/Global_Objects/Math/exp
page-type: javascript-static-method
browser-compat: javascript.builtins.Math.exp
sidebar: jsref
---
The **`Math.exp()`** static method returns [e](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/E) raised to the power of a number. That is
<!-- prettier-ignore-start -->
<math display="block">
<semantics><mrow><mrow><mo lspace="0em" rspace="0.16666666666666666em">πΌπππ.ππ‘π</mo><mo stretchy="false">(</mo><mi>π‘</mi><mo stretchy="false">)</mo></mrow><mo>=</mo><msup><mi mathvariant="normal">e</mi><mi>x</mi></msup></mrow><annotation encoding="TeX">\mathtt{\operatorname{Math.exp}(x)} = \mathrm{e}^x</annotation></semantics>
</math>
<!-- prettier-ignore-end -->
{{InteractiveExample("JavaScript Demo: Math.exp()")}}
```js interactive-example
console.log(Math.exp(0));
// Expected output: 1
console.log(Math.exp(1));
// Expected output: 2.718281828459 (approximately)
console.log(Math.exp(-1));
// Expected output: 0.36787944117144233
console.log(Math.exp(2));
// Expected output: 7.38905609893065
```
## Syntax
```js-nolint
Math.exp(x)
```
### Parameters
- `x`
- : A number.
### Return value
A nonnegative number representing e<sup>x</sup>, where e is [the base of the natural logarithm](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/E).
## Description
Because `exp()` is a static method of `Math`, you always use it as `Math.exp()`, rather than as a method of a `Math` object you created (`Math` is not a constructor).
Beware that `e` to the power of a number very close to 0 will be very close to 1 and suffer from loss of precision. In this case, you may want to use {{jsxref("Math.expm1")}} instead, and obtain a much higher-precision fractional part of the answer.
## Examples
### Using Math.exp()
```js
Math.exp(-Infinity); // 0
Math.exp(-1); // 0.36787944117144233
Math.exp(0); // 1
Math.exp(1); // 2.718281828459045
Math.exp(Infinity); // Infinity
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{jsxref("Math.E")}}
- {{jsxref("Math.expm1()")}}
- {{jsxref("Math.log()")}}
- {{jsxref("Math.log10()")}}
- {{jsxref("Math.log1p()")}}
- {{jsxref("Math.log2()")}}
- {{jsxref("Math.pow()")}}
|