undefined出现在几种情况和null值差别

一,undefined出现的几种情况。

1,在使用一个未声明的变量时。

  

1 function iter() {
2 alert(b);
3 }

 运行结果:

 

2,在使用一个已经声明但没有赋值的变量时。

 

1 var b;
2 function iter() {
3 alert(b);
4 }

运行结果:

3.使用了一个并不存在的对象属性时:

 

1 var ped = { upper: (point.x + point.y), lower: (point.x -point.y)};
2 function assign() {
3 alert(ped.high);
4 }

运行结果:

二、undefined与null值的区别。

    var b;
        function iter() {
            alert('typeof (b):' + typeof (b));
            alert('b == null:' + (b == null));
            alert(' b === null:' + (b === null));
        }  

运行结果:

(1)

(2)

(3)

posted @ 2010-11-24 22:55  空头支票  Views(119)  Comments(0)    收藏  举报