码迷,mamicode.com
首页 > 编程语言 > 详细

javascript 中null,undefined和空的应用

时间:2015-06-20 00:23:41      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

function demo(){
    alert(typeof a == "undefined");//true
}
function demo(){
    alert(a == null);//console error a is not defined
}
function demo(a){
    alert(typeof a == "undefined");//true
    alert(a == null);//true
}
function demo(){
    var a;
    alert(typeof a == "undefined");//true
    alert(a == null);//true
}
function demo(){
    var a=document.getElementById("name").value;//this node  exists! but it has no value
    alert(a == "");//true
    alert(a == null);//false
    alert(typeof a == "undefined");//false
}
function demo(){
    var a=document.getElementById("name").value;//this node is not here
    alert(a == "");//false
    alert(a == null);//true
    alert(typeof a == "undefined");//false
}
function(){
    alert(null == undefined);//true
    //使用typeof方法在前面已经讲过,null与undefined的类型是不一样的,所以输出"false"。而===代表绝对等于,在这里null === undefined输出false。
    alert(null === undefined);//false
    alert(typeof null == typeof undefined); //false
}


javascript 中null,undefined和空的应用

标签:

原文地址:http://my.oschina.net/hcliu/blog/469025

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!