 Logical Operators
Logical 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.
123456789let isSunny = true; let isWarm = false; let isRaining = false; if ((isSunny && isWarm) || !isRaining) { console.log("You can go outside!"); } else { console.log("Better stay indoors."); }
123456789let isSunny = false; let isWarm = true; let isRaining = true; if ((isSunny && isWarm) || !isRaining) { console.log("You can go outside!"); } else { console.log("Better stay indoors."); }
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 2. Kapitel 2
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Awesome!
Completion rate improved to 7.69 Logical Operators
Logical Operators
Svep för att visa menyn
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.
123456789let isSunny = true; let isWarm = false; let isRaining = false; if ((isSunny && isWarm) || !isRaining) { console.log("You can go outside!"); } else { console.log("Better stay indoors."); }
123456789let isSunny = false; let isWarm = true; let isRaining = true; if ((isSunny && isWarm) || !isRaining) { console.log("You can go outside!"); } else { console.log("Better stay indoors."); }
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 2. Kapitel 2