in window js 未定义和undifined的区别
浏览器报错:未定义和undifined不是同一概念,前者是没有申明,后者是没有赋值。
1:
<html>
<body>
<script>
if(!("a" in window)){
var a = 1;
}
alert(a);//undifined
function b(){
var c = 2;
}
alert(b);//函数b
//alert(c);//报错 c未定义
alert("c" in window);//false
alert(c);//报错 c未定义
</script>
</body>
</html>
2:
<html>
<body>
<script>
var a = 1
b = function a(x){
x && a(--x);
};
alert(a);//1
</script>
</body>
</html>
3:
<html>
<body>
<script>
if(!("" in window)){
var a = 1;
}
alert(a);//1
</script>
</body>
</html>
4:
<html>
<body>
<script>
var d;
alert(d);//undifined
var a = 1;
b = function a(x){
x && a(--x);
};
alert(a);//1
</script>
</body>
</html>
@江西-小若 总结