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

140
Views
when doing Comparison,is typeof necessary?

I am a junior backEnd developer.
My colleague do code review for my project.
I write a function as below without typeof.
He recommended use typeof for me when I do Comparison in this case.
I wanna know is typeof necessary in this case and why ??
I am happy my colleague give me some advices.
But I need key reason to push me change my coding style, Thank you.

let users = {
  Leo:{
    age:20,
    style:"Fire"
  },
  Kai:{
    age:30,
    style:"Ice"
  }
}

//My version
function getUser(name){
  let user = users[name];
  if(user === undefined){
    return false
  }
  // do something...
  return true
}

//Colleague version
function getUser(name){
  let user = false;
  if(typeof users[name] === 'undefined'){
    return false
  }
  user = users[name];
  // do something...
  return true
}
about 4 years ago · Juan Pablo Isaza
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!