Sitemap
Al-Hussein Abubakar

Al-Hussein Abubakar

Software Developer

Scope and Closure in JavaScript

1 min readApr 5, 2026

I just put up a new post on my blog about Scope & Closures in JavaScript.

Press enter or click to view image in full size

If you’ve ever wondered why your for loop with setTimeout keeps giving you the same number every time, or how some functions manage to “remember” variables even after they should have disappeared… this one breaks it down.

I used a simple office building analogy that actually helped it click for me, explained the differences between var, let, and const, and showed how closures work in real scenarios – like private counters, function factories, and keeping state in callbacks.

Get Al-Hussein Abubakar’s stories in your inbox

Join Medium for free to get updates from this writer.

It’s one of those core concepts that keeps biting people if they don’t fully get it. I tried to keep it straightforward with clear examples and the usual gotchas.

Check it out if you’re interested:

https://blog.al-husayn.dev/blog/scope-and-closures

Would love to know what you think, especially if you have your own tricks for explaining closures!

#JavaScript #WebDevelopment #Coding #JSconcepts

--

--