javascript判断变量是否定义
在javascript中使用一个js变量时,
例如:
if(hasLoaded){
//Do something here
}
如果此变量还未被定义,就会报错: 'xxxx' is #790000.
这时,就需要对这个变量进行判断:
if(typeof(hasLoaded) != 'undefined'){
if(hasLoaded){
//Do something here
}
}
在javascript中使用一个js变量时,
例如:
if(hasLoaded){
//Do something here
}
如果此变量还未被定义,就会报错: 'xxxx' is #790000.
这时,就需要对这个变量进行判断:
if(typeof(hasLoaded) != 'undefined'){
if(hasLoaded){
//Do something here
}
}