2-11 Undefined

千萬不要自己將變數的值設成undefined,以保證undefined都是js engine 所設的,方便debug

作者覺得叫notset 比較合適 😤

1
2
3
console.log(a);

//Uncaught ReferenceError: a is not defined
  • a does not exist in memory
1
2
3
4
5
var a;

console.log(a);

//undefined
  • a exists in memory, but is set to a special value - undefined
testing undefined value
1
2
3
4
5
6
7
8
9

var a;

if (a === undefined){
console.log("a is not defined");
}
else{
console.log("a is definded");
}