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.EThis 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,
- We create a variable
xand set it to 2. - We calculate
Math.Eraised to the power ofxusing theMath.pow()method. - The result is stored in the variable
result. - We log
resultto the console using theconsole.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,
- We create a variable
yand set it toMath.E. - We calculate the natural logarithm of
yusing theMath.log()method. - The result is stored in the variable
ln. - We log
lnto the console using theconsole.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,
- We create variables
P,r, andtrepresenting the principal amount, the annual interest rate, and the time in years, respectively. - We calculate the future value
Ausing the formulaP * Math.pow(Math.E, r * t). - The result is stored in the variable
futureValue. - We log
futureValueto the console using theconsole.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.