Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Math.exp: exponential function

Math.exp converts its argument to Number and returns an approximation of e raised to that power.

Version: ECMAScript 1 onward; example target: Node.js 24.22.2

Syntax

Math.exp(x)

Math.exp(x) applies ToNumber and computes eˣ as a Number. exp(+0) and exp(-0) are exactly 1, exp(+Infinity) is Infinity, and exp(-Infinity) is +0. Mathematical eˣ is positive for finite x, while the represented Number can overflow to Infinity or underflow to +0.

NaN or a missing argument produces NaN. A numeric string is converted, while a Symbol or BigInt throws TypeError; an object can invoke valueOf or toString. The result and overflow thresholds follow IEEE 754 representation, and the function approximation may be implementation-dependent.

The function is not a constructor and has been standard since ECMAScript 1. It naturally expresses continuous growth, such as principal * Math.exp(rate * time). When eˣ−1 is needed for very small x, use Math.expm1(x) because subtracting 1 from Math.exp(x) can lose significant digits.

Examples

const principal = 1000;
const annualRate = 0.05;
const years = 10;
const amount = principal * Math.exp(annualRate * years);
console.log(amount.toFixed(2));
console.log(Math.exp(0), Math.exp(1).toFixed(15));
console.log(Math.exp(-Infinity), Math.exp(Infinity));
console.log(Number.isNaN(Math.exp()));
try { Math.exp(1n); } catch (error) { console.log(error instanceof TypeError); }

Result

1648.72
1 2.718281828459045
0 Infinity
true
true

Sources