Every function is its own namespace. Variables defined with var
are confined to the namespace in which they are declared. They are said to shadow variables of the same name in outer scope. That is how it was in ES5.
The concept of block scope was introduced in ES2015 and gave us the const
and let
declarations that apply inside blocks, treating them as their own namespace, as well. While this may offer us the convenience of re-using variable names, it also affords the ability to keep names simple since they are well enough constrained that they can’t be misconstrued if we understand the nature and behavior of the block they are in. So, a
, b
, c
and x
and y
, and m
and n
or i
, j
, k
are all suitable variables.
In outer scope we are dealing with more defined objects that are accessed from all over the program whose names need to impart meaning so a reader will know their makeup and usage in the overall program.