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

222
Vistas
Advantage of inline boolean conditional vs explicit if statement?

Recently I came across this little bit of JS logic:

close(focusAfter) {
    if (! this.open) return;

    this.open = false;

    focusAfter && focusAfter.focus();
},

The truthy-ness check of focusAfter is clearly used as an inline conditional to make sure a valid object/element exists before calling .focus() on it.

It seems to me that the equivalent logic could be clarified when rewritten as:

if (focusAfter) focusAfter.focus();

My question is: is there any "not-immediately-obvious" advantage to the inline boolean-check-then-execution shown in the original example versus explicitly writing an inline if statement to "wrap" the executed logic (in this case, focusAfter.focus())?

about 4 years ago · Juan Pablo Isaza
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