vendredi 8 juillet 2016

Why is "0" true only in if-statement [duplicate]

This expression

if("0"){ alert("true");}else{alert("false");}

results "true".

Why is that, when

if("0" == true){alert("true");}else{alert("false");}

results "false"?

I'm used to

"0" == 0 == false

Seems like that does not hold true only in an if-statement.

Is this the intendet behavoir? Can some one shed some light on it?

Aucun commentaire:

Enregistrer un commentaire