I was reading a JS book and there was a question asking for output of below:
3e+3
It is giving me 3000
. Can someone explain why?
I was reading a JS book and there was a question asking for output of below:
3e+3
It is giving me 3000
. Can someone explain why?
3 Answers
Reset to default 9This is called scientific notation, the xey
means "x
times 10
to the power of y
"
In your case, 3 * Math.pow(10, 3); // 3000
e
declares an exponent. This is known as exponential or scientific notation.
3e+3
is equal to 3e3
(the +
defines a positive number rather than addition), which is equal to 3 * (10^3)
which is equal to 3 * (10*10*10)
which is equal to 3000.
It's simple scientific notation. 3e+3
is 3 times 10 to the 3rd power.