在javascript中使用一個js變量時,
例如:
if(hasLoaded){
//Do something here
}
如果此變量還未被定義,就會報錯: 'xxxx' is #790000.
這時,就需要對這個變量進行判斷:
if(typeof(hasLoaded) != 'undefined'){
if(hasLoaded){
//Do something here
}
}
例如:
if(hasLoaded){
//Do something here
}
如果此變量還未被定義,就會報錯: 'xxxx' is #790000.
這時,就需要對這個變量進行判斷:
if(typeof(hasLoaded) != 'undefined'){
if(hasLoaded){
//Do something here
}
}