我有一个行为奇怪的空变量。出于某种原因,我似乎无法检测到它是否为空!var 被称为emailFromUrl
.
console.log(emailFromUrl); //returns null
console.log(emailFormUrl.toString()); //returns null
console.log(emailFromUrl === null); //false!
console.log(emailFromUrl != null); //true!
console.log(typeof emailFromUrl); //string
console.log(!emailFromUrl); //false!
console.log(emailFromUrl === ""); //false
这到底是怎么回事?
答案:
console.log(emailFromUrl === 'null'); //true!
未经过滤的控制台日志:
Test71 | emailFromUrl : null | emailFromUrl === null : false | emailFromUrl != null : true | emailFromUrl.toString() : null | typeof emailFromUrl : string | !emailFromUrl : false | emailFromUrl === "" : false | emailFromUrl === "null" : true