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
  • 170
  • 1
  • 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
  • 41,872
  • 14
  • 128
  • 201
1

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

Raftx24
  • 151
  • 2
  • 11