When you declare a variable anywhere inside the function, the variable will become local to that function, as all the variable declarations are moved to the top of the function.
In your case,
console.log('a == 5 woot: ' + (a == 5).toString());
var a = 6;
Before you assign 6
to a
, a
will be undefined
, but the scope will be local.
You might want to read about variable hoisting example in the MDN docs.
And as per the same MDN var doc,
The scope of a variable declared with var is the enclosing function