Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

75
Visualizações
JavaScript AND / OR Operand

The priority of AND && is higher than OR ||. That's why it works before OR.

In the example below, 1 && 0 is calculated first.

alert( 5 || 1 && 0 ); // 5

I don't understand how this happens?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The left-hand side will be evaluated first. Please see example

a || (b * c);  // evaluate `a` first, then produce `a` if `a` is "truthy"
a && (b < c);  // evaluate `a` first, then produce `a` if `a` is "falsy"
a ?? (b || c); // evaluate `a` first, then produce `a` if `a` is not `null` and not `undefined`
a?.b.c;        // evaluate `a` first, then produce `undefined` if `a` is `null` or `undefined`

Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence

about 4 years ago · Juan Pablo Isaza Relatório

0

Please check Operator Precedence for more details.

Order is from left to right, when any of the early left part evaluates to be true, the rest of right side is not evaluated and is omitted.

console.log(5 || false); // 5
console.log(true || 5 || false); // true
console.log(false || 5 || 10); // 5
console.log(false || 10 || 5); // 10

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda