Truthy and Falsy values in JavaScript

Hey there, Grasshoppers. In JavaScript, the boolean can be either true or false. For example:

let x = 3;
if (x === 3) {
    console.log("true!");
}

This will print the string "true!" since x is equal to 3.

But what if we have an if statement like this?

let x = 3;
if (x) {
    console.log("true!");
}

This will also print "true!". Weird!

In JavaScript, there are 6 falsy values:

  1. false: The boolean type opposite to true.

  2. 0: The number 0.

  3. '': A string with a length of 0 and has no characters.

  4. NaN: Which means Not a Number, typically caused by some math problems.

  5. undefined: A data type before it’s defined.

  6. null: A data type that can be assigned to a blank space.

Any numbers other than 0, the string that is not empty, etc., is called truthy values. If you put these truthy values into an if statement, then the if statement will run.

Thanks!
P :slightly_smiling_face:


I don’t understand how to go on from where I am now.

1 Like

Hey there. If you have completed the puzzle, you will see a message where you will start over or continue to view your code as in the picture below:

And you can start over by pressing the arrow in a circle (which kinda look like a recycle icon), as show in the picture below:

Also, you can reset your progress by tapping on the 3 landscape lines ☰, then tap “Reset my progress” button.

Warning: All puzzles you completed and the marks you have from each completed puzzles will be removed, then you will have to start over.

Thanks,
P :slightly_smiling_face: