I have a null variable that is behaving weird. For some reason I can't seem to detect whether or not it is null! The var is called 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
What the heck is going on here?
The answer:
console.log(emailFromUrl === 'null'); //true!
The unfiltered console log:
Test71 | emailFromUrl : null | emailFromUrl === null : false | emailFromUrl != null : true | emailFromUrl.toString() : null | typeof emailFromUrl : string | !emailFromUrl : false | emailFromUrl === "" : false | emailFromUrl === "null" : true
Perhaps emailFromurl value is just a literal null string? ) That will explain all the results you get in your question, I think.
well the === operator checks the value and type. emailFromUrl is of type string not null which it why it evaluates to false there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With