if(thisVariable){
//do sth.
}
var thisVariable={};
if(thisVariable["thatProperty"]){
//do sth.
}
上面這行代碼,直接寫在js文件中,運行會報錯,第一個是變量未聲明,第二個是屬性未聲明。
可是,如果把這兩端代碼,放在一個函數中,則不會報錯。
function test(thisVariable){
if(thisVariable){
//do sth.
}
var thisVariable={};
if(thisVariable["thatProperty"]){
//do sth.
}
}
test();
誰能講下原因?
另外,能不能擴展地講下這方面的知識,總結一下