undefined和报错的区别:
1.变量声明未赋值:undefined
2.变量先使用再声明为undefined
console.log(a);
var a = 123;
3.变量没有被声明而直接被调用
function demo(){
var num = 1;
console.log(num) //1
}
demo();
console.log(num); //报错 num是局部变量,不能被全局访问
undefined和报错的区别:
1.变量声明未赋值:undefined
2.变量先使用再声明为undefined
console.log(a);
var a = 123;
3.变量没有被声明而直接被调用
function demo(){
var num = 1;
console.log(num) //1
}
demo();
console.log(num); //报错 num是局部变量,不能被全局访问