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

155
Vistas
JS shorterhand conditional?

I am using the following shorthand conditional in JS/jQuery:

var delay = $(this).data("delay") ? $(this).data("delay") : options.delay;

If the element has a data-delay attribute use that value, otherwise get the value from options.delay.

It seems excessive using $(this).data("delay") two times in the shorthand conditional. Is there a better way to do it?

Would var delay = $(this).data("delay") || options.delay; be a good solution? I am not sure if all browser supports it.

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

0

yes, you can use Nullish Coalescing Operator. A nullish value is a value that is either null or undefined.

So, you can use something like this:

var delay = $(this).data("delay") ?? options.delay;

You can read more about it on this page: https://www.javascripttutorial.net/es-next/javascript-nullish-coalescing-operator/

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