Home Communities
IT Knowledge
Inspiration
Languages
EN

# JavaScript - Math.E property example

7 points
Created by:
442

The `Math.E`Ā property returns eĀ mathematical constant (`2.718281828459045...`).

`e` is called as Euler's numberĀ or as Napier's constant. However, it was discovered by Jacob Bernoulli. ItĀ is a mathematical constant used as the base of the natural logarithm.

``````// ONLINE-RUNNER:browser;

console.log( Math.E ); // 2.718281828459045

console.log( Math.exp(1) ); // 2.718281828459045
console.log( Math.exp(2) ); // 7.38905609893065
console.log( Math.exp(3) ); // 20.085536923187668``````

## 1. Documentation

 Syntax `Math.E` Result `e`Ā number (`2.718281828459045...`). Description `E`Ā is a static property that keeps `e` number what is one of the most commonly used mathematical constants.

## 2. `e` number approximation example

To calculateĀ `e`Ā number following function with infinity series can be used - to get better precision infiniteĀ number of iterations with big precision numbers should be used.

``````// ONLINE-RUNNER:browser;

function computeE(iterations) {
var e = 0;

for (var i = 0; i < iterations; ++i) {
var divider = 1;

for (var j = 0; j < i; ++j) {
divider *= (j + 1);
}

e += (1 / divider);
}

return e;
}

console.log( computeE(  1 ) ); // 1
console.log( computeE(  2 ) ); // 2
console.log( computeE(  5 ) ); // 2.708333333333333
console.log( computeE( 10 ) ); // 2.7182815255731922
console.log( computeE( 20 ) ); // 2.7182818284590455
console.log( computeE( 50 ) ); // 2.7182818284590455``````

## References

1. e (mathematical constant) - Wikipedia

## Alternative titles

Join to our subscribers to be up to date with content, news and offers.

## Cross technology - Math.E

##### š
Get your tech brand or product in front of software developers.
For more information Contact us

Join