Reputation: 295
Say
a=""; // empty String
b=0;
then
a==b; // returns true
What Test could I build to return true only if I compare two empty strings or two zero's?
Upvotes: 2
Views: 1929
Reputation: 316
use === instead of == for checking undifined and zero or false compare
Upvotes: 1
Reputation: 43842
Use the strict comparison operator, ===
. This will not use JavaScript's default type coercion, so you will get the correct result.
"" === 0; // false
Upvotes: 8