DEV Community 👩‍💻👨‍💻

Discussion on: A tricky JavaScript interview question asked by Google

Collapse
 
roh_mish profile image
Rohan Mishra

Agree with you. At first I thought the same thing everyone else did. It would print out the value. But as soon as I saw the index 4, I knew exactly what was happening.

This is the sort of thing you usually don't spot while coding but once you see it happening (usually in test run), is trivial to debug and fix. For one, using let and const over var produces more sensible and predictable results.