Why "string" == ["string"] is true in JavaScript? -
i needed iterate thought object , i'm losing mind this.
var obj = { a:"here", b: ["here"]}; for(var o in obj){ alert(obj[o]=="here"); }
the == operator compare equality after doing necessary type conversions. === operator not conversion, if 2 values not same type === return false. it's case === faster, , may return different result ==. in other cases performance same.
it should using === instead of ==:
var obj = { a:"here", b: ["here"]}; for(var o in obj){ alert(obj[o]==="here"); }
Comments
Post a Comment