Member-only story
The Visual Guide To JavaScript Variable Definitions & Scope
(for new JavaScript learners)
Here’s a list of my best web development tutorials.
Complete CSS flex tutorial on Hashnode.
Ultimate CSS grid tutorial on Hashnode.
Higher-order functions .map, .filter & .reduce on Hashnode.
Follow me @ Twitter, Instagram & fb to never miss premium articles.
We often talk about scope differences between var, let and const. But even more often I still see learners struggling with fully grasping the idea of how it all works. I think it’s probably because concepts are rarely visualized.
Let’s literally — take a look.
Not all scopes are made alike.
Don’t memorize scope rules for each type of scope. Try to figure out the reason why it actually works this way. (Variable privacy, for example.)
Let’s start with the block scope – the most basic of them all.
A block scope is just {} brackets. They can be placed anywhere in your program. That doesn’t happen often, because usually {} are used together with for-loops, functions, classes, etc. But a plain…