Puzzle 3The Mathemagician
 const​ largeNumber = Math.pow(10, 16);
 const​ smallNumber = 1;
 
 console.log(largeNumber + smallNumber);

Guess the Output

images/aside-icons/important.png

Try to guess what the output is before moving to the next page.

images/hline.png

You might have expected the output to be 10000000000000001, but this code will actually log:

 10000000000000000
images/hline.png

Discussion

In JavaScript, the Math.pow() function can be used to raise a number to ...

Get JavaScript Brain Teasers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.