I'm a little confused on how setTimeOut works: why the callback function didn't got the values it needed when it was invoked, but got them from the bottom of the script?
I expected it to print 5 and not 7..
what am I missing ?
any help is appreciated, thanks!
let foo = () => {
console.log(x);
};
let x = 5;
setTimeout(foo, 0); //7
for (let i = 0; i < 10000000000; i++) {} //just to waste some time because the timeOut is actually 4ms
x = 7;