views:

228

answers:

7

How can you represent mathematical constant "e" as a value in JavaScript?

+13  A: 

It's as easy as

Math.E
Tim Down
+1 for the fastest gun! :)
Daniel Vassallo
Only just..... :)
Tim Down
+2  A: 

I believe Math.E is what you want.

David
+2  A: 

You could use the constant:

Math.E
Darin Dimitrov
+3  A: 

Answer was too short, so here is a much much longer version.

Math.E

Kristoffer S Hansen
+2  A: 

JavaScript provides many mathematical constants that can be accessed from the Math object.

The one you want is Math.E

codaddict
+8  A: 

Other ways include:

Math.exp(1)

Approximations:

3-sqrt(5/63)

or

(Math.PI^4 + Math.PI^5)^(1/6)

which are good to 7 digits

and

163^(32/163) which is good to 6 digits

gd047
+1 Approximations are good to know. The OP probably didn't know about Math.E, so he was probably looking for something along this line originally.
Danny
A: 

e is represented by Math.E. But if your intention is to compute e^x, don't write Math.E^x. Use Math.exp(x) instead. It wouldn't be the first time someone has asked for e when they really want exp.

Thank you, but I was actually looking for constant e, which is something like 2.7... I completely see and understand the trap you reference.