JavaScript Math E
Syntax & Examples


Math.E static-property

The Math.E property represents Euler's number, the base of natural logarithms, which is approximately equal to 2.718.


Syntax of Math.E

The syntax of Math.E static-property is:

Math.E

This E static-property of Math euler's number and the base of natural logarithms; approximately 2.718.



✐ Examples

1 Using Math.E to calculate an exponential value

In JavaScript, we can use the Math.E property to calculate exponential values.

For example,

  1. We create a variable x and set it to 2.
  2. We calculate Math.E raised to the power of x using the Math.pow() method.
  3. The result is stored in the variable result.
  4. We log result to the console using the console.log() method.

JavaScript Program

const x = 2;
const result = Math.pow(Math.E, x);
console.log(result);

Output

7.3890560989306495

2 Using Math.E in a natural logarithm calculation

In JavaScript, we can use the Math.E property to assist in natural logarithm calculations.

For example,

  1. We create a variable y and set it to Math.E.
  2. We calculate the natural logarithm of y using the Math.log() method.
  3. The result is stored in the variable ln.
  4. We log ln to the console using the console.log() method.

JavaScript Program

const y = Math.E;
const ln = Math.log(y);
console.log(ln);

Output

1

3 Using Math.E in compound interest formula

In JavaScript, we can use the Math.E property in the compound interest formula to calculate the future value of an investment.

For example,

  1. We create variables P, r, and t representing the principal amount, the annual interest rate, and the time in years, respectively.
  2. We calculate the future value A using the formula P * Math.pow(Math.E, r * t).
  3. The result is stored in the variable futureValue.
  4. We log futureValue to the console using the console.log() method.

JavaScript Program

const P = 1000;
const r = 0.05;
const t = 10;
const futureValue = P * Math.pow(Math.E, r * t);
console.log(futureValue);

Output

1648.7212707001282

Summary

In this JavaScript tutorial, we learned about E static-property of Math: the syntax and few working examples with output and detailed explanation for each example.