'is false in Javascript? What would be the safest way to distinguish between '' and boolean false?
We are using an external API that returns '' or boolean false, while Javascript seems to find both equal. eg:
var x = '';
if (!x) {
alert(x); // the alert box is shown - empty
}
if (x=='') {
alert(x); // the alert box is shown here too - empty
}
var z = false;
if (!z) {
alert(z); // the alert box is shown - displays 'false'
}
if (z=='') {
alert(z); // the alert box is shown here too - displays 'false'
}
How can we distinguish between the two?
+2
source to share
4 answers