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 }
时间: 2024-10-19 05:33:32