Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

336
Views
¿Cuál es la mejor manera de averiguar 'indefinido' en varias variables?

Cuando hay varias variables y descubre que incluso una de ellas no está undefined , ¿qué código es el mejor?

variable es como a continuación

 const [a, b, c] = [1, '4', undefined]
  1. usar Array.includes
 [a, b, c].map(e => typeof e).includes('undefined')
  1. uso for ... of
 for (const e of [a, b, c]) { if (typeof e === 'undefined') { // 'undefined' found } }
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Depende de lo que quieras decir con "el mejor código". Si le importa la legibilidad, debe elegir la forma funcional.

incluso uno de ellos es indefinido

Según la descripción, el método que buscas es some . Además, es mejor verificar si no está definido explícitamente, prefiriendo el operador typeof

 const array = [1, '4', undefined]; const isOneOfThemIsUndefined = array.some(e => typeof e === 'undefined'))

about 4 years ago · Juan Pablo Isaza Report

0

Una simple llamada includes servirá, sin el tipo de typeof :

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

0

 const array = [1, '4', undefined]; const isOneOfThemIsUndefined = array.filter(Boolean) console.log(isOneOfThemIsUndefined) // => [1, '4',]
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!