How I understand it, there are two "a" variables.
One global, and one within the scope of the brackets.
On the first assignment, you are assigning it to the global.
When you declare the "a" function. It has local scope.
It assigns the current value in "a" to the global one.
Then when you assign a value to "a" again, it assigns it to the local scope variable.
For some reason, redeclaring the function name makes it assign local variable's value to the global variable. No idea why.
var a = [] // assigns to global
if (true) {
a = 1 // assigns to global
function a() {} // pushes value to global and creates a local "a" variable
a = 2 // assigns to local
function a() {} // pushes value to global
a = 3 // assigns to local
console.log('0: ', a) // outputs the local varaible
}
console.log('1: ', a) // outputs the last pushed global which is 2