undefined==null引發(fā)的兩者區(qū)別與聯(lián)系第2/3頁(yè)
更新時(shí)間:2007年12月22日 01:11:24 作者:
undefined==null引發(fā)的兩者區(qū)別與聯(lián)系
在javascript中什么情況出現(xiàn)下面三種情況: null undefined “ ”
文件1:null_undefined.html
文件2:null_undefined.js
1
null_undefined.html
【見(jiàn)文章評(píng)論一】
null_undefined.js
var test = function()
{
alert(window.aiter2008); //彈出undefined window空間中沒(méi)有aiter2008這個(gè)變量
alert(document.getElementById("test_text1111")); //null 在上面的null_undefined.html文件中沒(méi)有test_text1111元素
var testText = document.getElementById("test_text").value; // test_text輸入框中沒(méi)有輸入任何元素
alert(testText==""); //true
alert(testText==null); //false
}
這次測(cè)試可以得到結(jié)論:
一個(gè)對(duì)象中沒(méi)有指定的變量,而要使用,會(huì)出現(xiàn) undefined
Html中沒(méi)有的元素,通過(guò)document.getElementById("")查找的結(jié)果為: null
Html中有的元素,但是沒(méi)有任何值,通過(guò)document.getElementById("")查找的結(jié)果為:” ”; 不是null
2 null_undefined.html文件不變
null_undefined.js
var test = function()
{
var testText = document.getElementById("test_text");
var testName = testText.name;
var testUn = testText.name11;
alert("test_text's name::"+testName); // test_text's name:: test_text
alert("test_text's name11:::"+testUn); // test_text's name11:::undefined
}
結(jié)論
一個(gè)對(duì)象沒(méi)有的屬性,調(diào)用會(huì)出現(xiàn): undefied 這和調(diào)用window的aiter2008屬性一樣
您可能感興趣的文章:
- js判斷undefined類(lèi)型,undefined,null, 的區(qū)別詳細(xì)解析
- JavaScript null和undefined區(qū)別分析
- JavaScript Undefined,Null類(lèi)型和NaN值區(qū)別
- JS基礎(chǔ)之undefined與null的區(qū)別分析
- Javascript 中 null、NaN和undefined的區(qū)別總結(jié)
- javascript中的undefined 與 null 的區(qū)別 補(bǔ)充篇
- 詳解JavaScript中undefined與null的區(qū)別
- js中 關(guān)于undefined和null的區(qū)別介紹
- JavaScript中undefined和null的區(qū)別
- 一文讓你徹底弄懂js中undefined和null的區(qū)別
相關(guān)文章
微信小程序使用map組件實(shí)現(xiàn)獲取定位城市天氣或者指定城市天氣數(shù)據(jù)功能
這篇文章主要介紹了微信小程序使用map組件實(shí)現(xiàn)獲取定位城市天氣或者指定城市天氣數(shù)據(jù)功能,涉及微信小程序map組件結(jié)合微信API獲取天氣信息相關(guān)操作技巧,需要的朋友可以參考下2019-01-01一文詳解Web Audio瀏覽器采集麥克風(fēng)音頻數(shù)據(jù)
這篇文章主要為大家介紹Web Audio瀏覽器采集麥克風(fēng)音頻數(shù)據(jù)實(shí)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03JavaScript自定義日歷實(shí)現(xiàn)簽到功能
這篇文章主要為大家詳細(xì)介紹了JavaScript自定義日歷實(shí)現(xiàn)簽到功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08js實(shí)現(xiàn)鼠標(biāo)懸停圖片上時(shí)滾動(dòng)文字說(shuō)明的方法
這篇文章主要介紹了js實(shí)現(xiàn)鼠標(biāo)懸停圖片上時(shí)滾動(dòng)文字說(shuō)明的方法,涉及js操作鼠標(biāo)事件的使用技巧,需要的朋友可以參考下2015-02-028個(gè)開(kāi)發(fā)者必須知道的JavaScript深層概念(推薦)
JavaScript有一個(gè)名為“調(diào)用堆?!保–all Stack)的簡(jiǎn)單列表,它逐一管理任務(wù)(堆棧算法),但是當(dāng)異步任務(wù)被傳遞時(shí),JavaScript會(huì)把它彈出到web API,瀏覽器就會(huì)處理它,這篇文章主要介紹了8個(gè)開(kāi)發(fā)者必須知道的JavaScript深層概念,需要的朋友可以參考下2022-10-10