Booleans and comparisons
True and false
- A boolean is one of just two values:
trueorfalse. - Compare values to get a boolean:
===(equal),!==(not equal),<><=>=.

console.log(5 === 5); // → true
console.log(3 > 7); // → false
Combine tests
&&means and — true only when both sides are true.||means or — true when at least one side is true.!means not — it flipstrueandfalse.
console.log(true && false); // → false
console.log(!true); // → false
Truth table — try every input
&& (and) is true only when ambas are true. || (or) is true when at least one is.
Watch out
- Always compare with
===, not==. The older==quietly converts types:0 == ""istrue! ===checks value and type, which is what you almost always want.
Common mistakes
- Prefer
===(strict) over==, which does surprising type coercion. &&is AND,||is OR,!is NOT.
Now you try
- Each task logs
trueorfalse. - Press Check answer to test it.
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
Utilice === to log whether 10 equals 10 (it is true).
Haz clic en Ejecutar para ver la salida aquí.
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
Log whether 8 is greater than 3 (it is true).
Haz clic en Ejecutar para ver la salida aquí.
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
let n = 8. Log whether n is even by testing n % 2 === 0 (it is true).
Haz clic en Ejecutar para ver la salida aquí.
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
let age = 15. Use && to log whether the age is from 13 hasta 19 (a teenager) — it is true.
Haz clic en Ejecutar para ver la salida aquí.