Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3e+3 = 3000 - JavaScript query

Tags:

javascript

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?

like image 256
JS- Avatar asked Dec 02 '22 18:12

JS-


2 Answers

This is called scientific notation, the xey means "x times 10 to the power of y"

In your case, 3 * Math.pow(10, 3); // 3000

like image 99
Paul S. Avatar answered Dec 10 '22 12:12

Paul S.


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.

like image 39
James Donnelly Avatar answered Dec 10 '22 13:12

James Donnelly