var has always had this special aura of misconception — this probably because of how the behaviour of variables declared with
var distinguishes from most other programming languages. With that said, the whole thing has a pretty natural explanation — the scope.
The thing is,
var is function scoped. This type of scope acts a bit different from the more heavily used block scope.
Let’s look at what this means.
var — function scope
As mentioned, a variable being declared using
... read the whole story at www.deadcoderising.com.
var will be function scoped, meaning it will exist within the scope of the function it’s declared inside of.