Programming interviews are hard. Live coding during the interview is even harder.
I have a feeling that as soon as I have to type code in front of ...
For further actions, you may consider blocking this person and/or reporting abuse
Really well written! One minor thing, based on that loop, I believe it will log 0, 1, 2 and not 1, 2, 3? That detail doesn't effect all the wonderfully explained concepts though!
ups :) you are absolutely right, thank you for pointing this out :)
fixed
I believe before the addition of
let
one way to solve this would be to wrap the call tosetTimeout
in an IIFE. I guess by immediately invoking the outer function with the current value ofi
it seals the value at that moment vs getting it from the global scope when the inner function is called.Maciek this is great! The final recap really tied it together, and now I understand the logic behind this question much more thoroughly. Excellent stuff, can't wait for the next one.
I'm blushing, thank you ;)
The backpack analogy is a good one. I often think the names given to these concepts make them harder to learn. Closures to me would indicate some kind of ending or return. I assume it is something to do with being enclosed, maybe? Similarly the "rest parameter" sounds like it's going to have a little pause before entering your function. I had a less imaginative way to remember closures - savedScopeForLater! From now on though, Closure = backpack!
Great article, Maciek!
Thank you very much. In a days I will be interviewed and it's very helpful!!! 👌👌👌
Good luck on the interview, I hope you will get the job :D
Thanx) And I hope😊
Yet a little another solution
Will this guarantee that it emits 0,1,2? Since setTimeout() is async, I don't think it guarantees execution order.
This is pure essentials in JS. Good wrap up! Thanks for writing and sharing.