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: 
Because `var a=b=5;` statement defines only local `a` variable and in fact is interpreted like

```
var a = (b=5);

```

which equals to

```
b = 5;
var a = 5;

```

which assigns `5` to a global `b` variable and defines a local `a` variable.

The proper way to define 2 local variables without value repetition would be

```
var b = 5, a = b;

```
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.