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

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -