This snippet results in a JavaScript runtime error: (foo
is not defined)
if (foo) {
// ...
}
I have to define foo
This is not a strange question coz I'm on the same boat :p
I reach here after googling "javascript use variable undefined". I got confuse coz I've seen somewhere that people can simply use undefined variable in a loop.
Maybe I saw it on different language
I've found it. The first codes successfully executed while the second codes runtime error.
First Codes:
test();
function test() { x = 4; }
console.log(x); //this produce 4
Second Codes:
test();
function test() { x[0] = 1; }
console.log(x[0]);