Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Logical Operators | Building Conditions and Repetition
Conditional Statements and Loops in JavaScript

bookLogical Operators

Imagine you want to decide whether to go outside. You might think: "I'll go out if it's sunny and warm, or if it's not raining." This everyday reasoning is very similar to how you combine conditions in JavaScript using logical operators.

  • The && operator means and, both conditions must be true;
  • The || operator means or, at least one condition must be true;
  • The ! operator means not, it flips a condition to its opposite.
123456789
let isSunny = true; let isWarm = false; let isRaining = false; if ((isSunny && isWarm) || !isRaining) { console.log("You can go outside!"); } else { console.log("Better stay indoors."); }
copy
123456789
let isSunny = false; let isWarm = true; let isRaining = true; if ((isSunny && isWarm) || !isRaining) { console.log("You can go outside!"); } else { console.log("Better stay indoors."); }
copy
question-icon

Fill in the blank to combine two conditions so the code prints "Bring an umbrella!" only if it is raining or it is cloudy.

let isRaining = false; let isCloudy = true; if () { console.log("Bring an umbrella!"); }
Bring an umbrella!

Click or drag`n`drop items and fill in the blanks

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 2

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Awesome!

Completion rate improved to 7.69

bookLogical Operators

Desliza para mostrar el menú

Imagine you want to decide whether to go outside. You might think: "I'll go out if it's sunny and warm, or if it's not raining." This everyday reasoning is very similar to how you combine conditions in JavaScript using logical operators.

  • The && operator means and, both conditions must be true;
  • The || operator means or, at least one condition must be true;
  • The ! operator means not, it flips a condition to its opposite.
123456789
let isSunny = true; let isWarm = false; let isRaining = false; if ((isSunny && isWarm) || !isRaining) { console.log("You can go outside!"); } else { console.log("Better stay indoors."); }
copy
123456789
let isSunny = false; let isWarm = true; let isRaining = true; if ((isSunny && isWarm) || !isRaining) { console.log("You can go outside!"); } else { console.log("Better stay indoors."); }
copy
question-icon

Fill in the blank to combine two conditions so the code prints "Bring an umbrella!" only if it is raining or it is cloudy.

let isRaining = false; let isCloudy = true; if () { console.log("Bring an umbrella!"); }
Bring an umbrella!

Click or drag`n`drop items and fill in the blanks

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 2
some-alt