Booleans and comparisons · Booleans e comparações
True and false
- A boolean is one of just two values:
trueorfalse. - Compare values to get a boolean:
===(equal),!==(not equal),<><=>=.
Verdadeiro e falso
- Um booleano é um de apenas dois valores:
trueoufalse. - Compare valores para obter um booleano:
===(igual),!==(desigual),<><=>=.
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.
Combine testes
&&significa e — verdadeiro apenas quando ambos os lados são verdadeiros.||significa ou — verdadeiro quando pelo menos um lado é verdadeiro.!significa não — ele invertetrueefalse.
console.log(true && false); // → false
console.log(!true); // → false
Truth table — try every input · Tabela-verdade — tente toda entrada
&& (and) is true only when both · ambos are true. || (or) is true when at least one is. · && (and) é verdadeiro apenas quando ambos são verdadeiros. || (or) é verdadeiro quando pelo menos um é.
Watch out
- Always compare with
===, not==. The older==quietly converts types:0 == ""istrue! ===checks value and type, which is what you almost always want.
Atenção
- Sempre compare com
===, não==. O antigo==converte tipos silenciosamente:0 == ""étrue! ===verifica valor e tipo, o que você quase sempre quer.
Common mistakes
- Prefer
===(strict) over==, which does surprising type coercion. &&is AND,||is OR,!is NOT.
Erros comuns
- Prefira
===(estrito) sobre==, que faz coerção de tipo surpreendente. &&é AND,||é OR,!é NOT.
Now you try
- Each task logs
trueorfalse. - Press Check answer to test it.
Agora você tenta
- Cada tarefa registra
trueoufalse. - Pressione Check answer para testá-lo.
Use === to log whether 10 equals 10 (it is true). · Use === para fazer log se 10 é igual a 10 (é true).
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Log whether 8 is greater than 3 (it is true). · Faça log se 8 é maior que 3 (é true).
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
let n = 8. Log whether n is even by testing n % 2 === 0 (it is true). · let n = 8. Faça log se n é par testando n % 2 === 0 (é true).
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
let age = 15. Use && to log whether the age is from 13 to · até 19 (a teenager) — it is true. · let age = 15. Use && para fazer log se a idade está entre 13 e 19 (um adolescente) — é true.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.