If (youHit) / if (youHit===1) are they the same?


Why don't I need to write:
if (youHit**===1**){
console.log ("You hit!");

Are they the same?


if(youHit) basically meansif(youHit==true) . So if you hit the dragon you console.log("You Hit") .if(youHit==1) means if the variable youHit is 1 whitch is not the same as before.

Hope this helped!

Have a merry christmass! :evergreen_tree:


but if (youHit ==1), it means that (youHit==true), right?


no it dosent... if (youHit ==1) is an integer value while (youHit==true) is a boolean value




JavaScript will read any non-zero value as truthy and 0 value as falsy. To test whether the value is truthy or falsy, just use the coercive equality operator:

1                  == true  // true
0                  == false // true
-1                 == true  // true
"non-empty string" == true  // true
""                 == false // true - empty strings have false value

What CC meant by "reads as true" is basically being truthy.


thank you for explaining, this was what I was confused about (and why I was looking up this question)