代码是:
var someVariable; // this variable is declared but not initialised...
alert(typeof someVariable); // alerts 'undefined'
alert(typeof notDeclared); // also alerts 'undefined' irrespective
// of the fact it has not been declared..
似乎有点混乱。现在,如果我这样做
alert(someVariable); // again alerts 'undefined'
alert(notDeclared); // causes an error
jsFiddle 链接:http: //jsfiddle.net/gjYZt/2/
如果'typeof notDeclared'未定义,那么当我警告'notDeclared'时,它也应该警告'undefined'而不是给出错误。