Skip to the content

&&, || and !

JavaScript · Unit 2: Conditionals

&& joins two conditions and gives true only if both are met. If one fails, the whole thing is false.

It is written with two & signs.

console.log(5 > 3 && 4 > 1);
console.log(5 > 3 && 2 > 4);

Prints

true
false

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Predict the output

    What does this code print?

  2. 2. Complete the code

    You pass with 60 or more and fewer than 3 absences. Fill in the condition.

  3. 3. Predict the output

    What does this code print?

  4. 4. Find the bug

    It should say there is stock only for sizes S and M. This one is an L. Which line has the error?

  5. 5. Predict the output

    What does this code print?

  6. 6. Complete the code

    Fill in the blank so it says whether there is room on the bus.

  7. 7. Multiple choice

    Kids under 5 and adults over 65 get in free. Which condition goes in the if?

  8. 8. Predict the output

    The top score is 100, and this one is 101. What does it print?

  9. 9. Put the lines in order

    The person types 101. Put the lines in order to accept only scores from 0 to 100.

  10. 10. Predict the output

    What does this code print?

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →