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

344
Visualizações
What's the best way to figure out 'undefined' in several variables?

When there are several variables and figure out even one of them is undefined, which code is the best one?

variable is like below

const [a, b, c] = [1, '4', undefined]
  1. use Array.includes
[a, b, c].map(e => typeof e).includes('undefined')
  1. use for ... of
for (const e of [a, b, c]) {
    if (typeof e === 'undefined') {
        // 'undefined' found
    }
}
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

It depends on what you mean under "the best code". If you care about readability, you should choose the functional way.

even one of them is undefined

According to the description, the method you are looking for is some. Also, it's better to check for undefined explicitly, preferring the typeof operator

const array = [1, '4', undefined];

const isOneOfThemIsUndefined = array.some(e => typeof e === 'undefined'))

about 4 years ago · Juan Pablo Isaza Relatório

0

A simple includes call will do, without the typeof mapping:

[a, b, c].includes(undefined)
about 4 years ago · Juan Pablo Isaza Relatório

0

 const array = [1, '4', undefined];
 const isOneOfThemIsUndefined = array.filter(Boolean)

 console.log(isOneOfThemIsUndefined)

// =>  [1, '4',]
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