The magic inside javascript for-loops

Welcome JsDev's, Working with for loops are always complicated, mostly for-loops inside async blocks. so here are some examples where i felt OMG, what is happening, Example 1: for(var i=0; i<3; i++) { setTimeout(()=>console.log(i)); } Output: 3 3 3 How? Lexical scoping and closures:…