Closures in Loops; Be Careful Enough [RE#2]
Closures could sometimes be tricky to the point that you may find out things too late/costly.
Look at this code fragment:
let a = [1, 2, 3];
let fn = [];
for (x of a) fn.push(() => x);
for (f of fn) console.log(f());
Simply, we've added three functi...
babakks.hashnode.dev2 min read