This loop is supposed to blink five LEDs in sequence in a browser simulation: for (var i = 0; i < 5; i++) { setTimeout(function () { toggle(i); }, i * 200); }. Instead toggle is called five times with 5. Changing var to let fixes it and I get 0 to 4, but I do not understand why one keyword changes what the callbacks see.
What is the actual difference between var, let and const, and is there any reason to still use var?




