2

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?

Bob S
  • 305
  • 2
  • 11
  • 1
    here is a really good post of == vs. === http://stackoverflow.com/questions/523643/difference-between-and-in-javascript – taesu Jan 28 '15 at 22:20
  • possible duplicate of [Does it matter which equals operator (== vs ===) I use in JavaScript comparisons?](http://stackoverflow.com/questions/359494/does-it-matter-which-equals-operator-vs-i-use-in-javascript-comparisons) – Alexis King Jan 28 '15 at 22:21

2 Answers2

7

Use the strict comparison operator, ===. This will not use JavaScript's default type coercion, so you will get the correct result.

"" === 0; // false
Alexis King
  • 43,109
  • 15
  • 131
  • 205
1

use === instead of == for checking undifined and zero or false compare

Raftx24
  • 306
  • 5
  • 11