Search posts, tags, users, and pages
Timeouts, Closures, JavaScript and references.
Tiger Abrodi
@tigerabrodi · Germany
Obsessed with crafting software.
Just a guy who loves to write code and watch anime.
Markdown supported · ⌘↵ to post
rameztayem
let x = 1; const fn = () => console.log(x); // Captures x=1 x = 2; setTimeout(fn, 1000); // Will print 1, not 2
this will print 2 not 1 i have tried it any explaination why?
rameztayem
let x = 1; const fn = () => console.log(x); // Captures x=1 x = 2; setTimeout(fn, 1000); // Will print 1, not 2
this will print 2 not 1 i have tried it any explaination why?