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

163
Visualizações
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 Respostas
Responde à pergunta

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 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