Booleans and comparisons · Booleanos y comparaciones
True and false
- A boolean is one of just two values:
trueorfalse. - Compare values to get a boolean:
===(equal),!==(not equal),<><=>=.
Verdadero y falso
- Un booleano es uno de solo dos valores:
trueofalse. - Compara valores para obtener un booleano:
===(igual),!==(diferente),<><=>=.
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.
Combinar pruebas
&&significa y — es verdadero solo cuando ambos lados son verdaderos.||significa o — es verdadero cuando al menos uno de los lados es verdadero.!significa no — inviertetrueafalsey viceversa.
console.log(true && false); // → false
console.log(!true); // → false
Truth table — try every input · Tabla de verdad — prueba cada entrada
&& (and) is true only when both · ambas are true. || (or) is true when at least one is. · && (y) es verdadero solo cuando ambos son verdaderos. || (o) es verdadero cuando al menos uno lo es.
Watch out
- Always compare with
===, not==. The older==quietly converts types:0 == ""istrue! ===checks value and type, which is what you almost always want.
Ten cuidado
- Siempre compara con
===, no con==. El antiguo==convierte tipos en silencio:0 == ""estrue! ===verifica el valor y el tipo, lo cual es lo que casi siempre deseas.
Common mistakes
- Prefer
===(strict) over==, which does surprising type coercion. &&is AND,||is OR,!is NOT.
Errores comunes
- Prefiere
===(estricto) sobre==, que realiza una coerción de tipo sorprendente. &&es Y,||es O,!es NO.
Now you try
- Each task logs
trueorfalse. - Press Check answer to test it.
Ahora tú intentas
- Cada tarea imprime
trueofalse. - Presiona Comprobar respuesta para verificarla.
Use === to log whether 10 equals 10 (it is true). · Usa === para registrar si 10 es igual a 10 (es true).
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
Log whether 8 is greater than 3 (it is true). · Registra si 8 es mayor que 3 (es true).
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
let n = 8. Log whether n is even by testing n % 2 === 0 (it is true). · let n = 8. Registra si n es par probando n % 2 === 0 (es true).
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
let age = 15. Use && to log whether the age is from 13 to · hasta 19 (a teenager) — it is true. · let age = 15. Usa && para registrar si la edad está entre 13 y 19 (un adolescente) — es true.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.