Why does the second function output an empty array?
var global = ["abc"];
function test1() {
var g = global || [];
console.log(g); //outputs: ["abc"]
}
function test2() {
var global = global || [];
console.log(global); //outputs: []
}
While it seems like it should work because assignment works right to left, you need to consider that variable declarations are hoisted.
To the interpreter, your code actually looks like this: