js判斷是否爲空和typeof用法

(1)typeof用法

typeof的運算數未定義,返回的就是 "undefined".

運算數爲數字 typeof(x) = "number"

字符串 typeof(x) = "string"

布爾值 typeof(x) = "boolean"

對象,數組和null typeof(x) = "object"

函數 typeof(x) = "function"


(2)js判斷是否爲空

var exp = null;
if (!exp && typeof(exp)!="undefined" && exp!=0 && exp!='')
{
    alert("is not null");
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章