Question: Why does the following code result in logging of `b` while `a` is still `undefined`?

```
(function(){ var a=b=5; })();
console.log('b:'+b);
console.log('a:'+a);

```

Answer: 
In JavaScript if you ommit the var keyword before a variable, it will be considered as global.
So here **b** is a global variable and **a** is only a local to that function's scope.
That's why you are getting the error while accessing the **a**.
A variable can be defined in 2 ways:

* var a= 5 // first
* a=5 // Second

In first way, `a` is a local variable, but in second way, it becomes a global variable.

So, when you do `var a=b=5`, `b` is a global variable and hence retains value.