0

Hi can you please tell me why aleert is display when I am comparing the values

a is undefined and b is null .how they are equal ? http://jsfiddle.net/4fmzjhge/

var a
var b=null;
//value of a
alert(a);
//
alert(b)
if(a==b){alert('test');}

alert(typeof(a));

alert(typeof(b));
Pallavi Sharma
  • 635
  • 2
  • 14
  • 43
  • 1
    use === instead of == and it will work – mulla.azzi Sep 01 '14 at 07:24
  • yes why == give alert my Question is that == check only value and === check value as well datatype.But both value is different one is null and second is "undefined" – Pallavi Sharma Sep 01 '14 at 07:25
  • Read this too for more info :http://stackoverflow.com/questions/5076944/what-is-the-difference-between-null-and-undefined-in-javascript – Sunil Hari Sep 01 '14 at 07:25
  • your answer is very clearly explained here http://stackoverflow.com/questions/5101948/javascript-checking-for-null-vs-undefined-and-difference-between-and – Tushar Raj Sep 01 '14 at 07:57

1 Answers1

0

because undefined, false, null, 0 is have same level in condition statement it is = false

kefy
  • 535
  • 2
  • 10