标签:运算符 false efi bool lse 包括 typeof oat float
1.判断undefined:
var tmp = undefined;if (typeof(tmp) == "undefined"){ console.log("undefined");}说明:typeof 返回的是字符串,有六种可能:"number"、"string"、"boolean"、"object"、"function"、"undefined"
2.判断null:
var tmp = null;if (!tmp && typeof(tmp)!="undefined" && tmp!=0){ console.log("null");}var tmp = 0/0;
if(isNaN(tmp)){ console.log("NaN"); }说明:如果把 NaN 与任何值(包括其自身)相比得到的结果均是 false,所以要判断某个值是否是 NaN,不能使用 == 或 === 运算符。var tmp = undefined;
if (tmp == undefined) {
console.log("undefined == undefined");
}
var tmp = undefined;
if (tmp == null) {
console.log("null == undefined");
}
结论:null == undefined
5.判断undefined、null与NaN:
var tmp = null;
var tmp1 = undefined;
var tmp2 = NaN;
if (!tmp) {
console.log("null or undefined or NaN");
}
if (!tmp1) {
console.log("null or undefined or NaN");
}
if (!tmp2) {
console.log("null or undefined or NaN");
}
结果:都打印
标签:运算符 false efi bool lse 包括 typeof oat float
原文地址:https://www.cnblogs.com/lzghyh/p/11871386.html