DEV Community

Adrian
Adrian

Posted on

console.log(9007199254740992 + 1); Surprised by the result?

What is the output of the following JavaScript code:

console.log(100 + 200);
console.log(9007199254740992 + 1);

Try to estimate the answer... and then run the above code in your favorite JavaScript environment.

Are you surprised by the result?! There is a very simple explanation. Can you find it?

Top comments (1)

Collapse
 
akashkava profile image
Akash Kava

Well no, because all numbers have definitive limit in every computing platform/framework/language. And I can guess, it is number overflow. Languages like c# throws an exception in some cases.

I was expecting an overflow exception, but JavaScript didn't so that was surprise !!