Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

141
Vistas
Why does this short circuit evaluation return undefined if first value is false?

I have an example similar to this where the first expression evaluates to false and the second is undefined but the overall expression returns undefined into valueResult, shouldn't the first false value terminate the check and return false?

valueResult = false && 10 === 5 ? 'match' : undefined

I have added console log statements and a debugger and this is what is happening, however when I do false && undefined on the browser console, it returns false.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

&&-operator has higher precedence then the ternary operator. That's why following is happening:

Basically you have a ternary operator (false && (10 === 5) ? : 'match' : undefined. 10 === 5 evaluates to false and false && false also results in false. Thats why undefined and not 'match' is returned.

To fix this, add parentheses after && like this:

 false && (10 === 5 ? 'match' : undefined)
about 4 years ago · Juan Pablo Isaza Denunciar

0

In your updated example, the logical AND … && … has a higher order of precedence (5) than the evaluation of the ternary … ? … : … (3).

Check out the table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#table

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda