mercredi 1 juillet 2015

Javascript "implicit" condition in IF statements [duplicate]

This question already has an answer here:

This is so basic that it may well already exist somewhere here. Apologies for not having found it - my knowledge of coding lingo must be too limited to be an effective searcher...

I have seen several instances of code where a condition does not have an equal sign. For example:

var test = true;
if (test){
   console.log("success");
} else {
   console.log("failure");
}

outputs success whereas if var test = false, the output would be failure.

What exactly is the implicit condition (e.g., == true vs === true)? And what is the full set of values for test that would output failure? It is just false, 0, "", null, undefined, and NaN?

Aucun commentaire:

Enregistrer un commentaire