Skip to content
Tutorials Center
My learning

Topics

JavaScript Reference ยท Math

Math.exp()

Reference for Math.exp(): computing e raised to a power, continuous growth and decay, the accurate expm1() variant, and its relation to Math.log().

Math.exp(x) returns e raised to the power x, where e is Euler's number, about 2.71828. It is the inverse of Math.log(): Math.exp(Math.log(5)) gives 5 (up to a rounding error).

The exponential function describes continuous growth and decay, such as compound interest, population models, radioactive decay and the sigmoid function in machine learning.

JavaScript
Math.exp(x)

Try it

JS e to the power x

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS Growth, decay and the sigmoid

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Syntax

JavaScript
Math.exp(x)
Math.expm1(x)
Name Description
x The exponent. A number or a value that converts to one.

Return value: e ** x. The result is Infinity when x is too large (about 710 or more), 0 when x is -Infinity or very negative, and NaN for non-numeric input. Math.expm1(x) returns e ** x - 1.

Exceptions: a BigInt argument throws a TypeError.

Usage notes

  • Same idea as Math.E ** x, but Math.exp(x) is more accurate because Math.E is itself rounded.
  • Overflow and underflow. Math.exp(709) is finite and Math.exp(710) is Infinity; strongly negative inputs turn into 0. For the sigmoid and softmax functions, subtract the maximum input first to keep the values in range.
  • Math.expm1(x) gives e ** x - 1 without losing digits when x is tiny. The plain subtraction Math.exp(x) - 1 cancels most significant digits near zero.
  • Inverse. Math.log() undoes Math.exp(), and Math.exp() undoes Math.log().
  • Hyperbolic functions such as Math.cosh() and Math.tanh() are built from exponentials.
  • Discrete versus continuous growth: compare (1 + r) ** t with Math.exp(r * t).

Browser support

Math.exp() is supported everywhere. Math.expm1() is part of ES2015.