DEV Community

Discussion on: Guess the output

Collapse
 
siddharthshyniben profile image
Siddharth

TL;DR If you use var this will happen, try using let


var is not block scoped, this is a limitation from the days of old JavaScript. Nowadays you should use the modern let or const.

Some resources: