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

339
Views
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 answers
Answer question

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 Report

0

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

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