0

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?

malty-ale
  • 21
  • 3
  • 1
    The key words to search for are `truthy` and `falsey`. Any expression that evaluates to `truthy` will satisfy an `if` in Javascript. Lots of different values are `truthy`, not just `true`. – jfriend00 Jul 02 '15 at 06:26
  • @jfriend00 thanks - totally covers it. just didn't know the terms... – malty-ale Jul 02 '15 at 06:28

0 Answers0