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

221
Views
Why should we not explicitly assign undefined to a variable in javascript?

I have heard it in some videos and blogs that we should not assign undefined to a variable in JavaScript explicitly in our code, instead we should use null. Why though?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

My conclusion is that undefined, lets us know that a variable has not been initialized yet, if we initialize it in our code and then make it undefined at a later stage, then it would lose its purpose hence we should use null, instead.

There can be a case, in which your logic dictates that if you get an undefined variable then the flow should be different than the case wherein you get null.

about 4 years ago · Juan Pablo Isaza Report

0

Undefined indicates a very specific use case. It means that the value is not initialized, and you don't know what the value is. The problem is you would not want to get "undefined" as an output while working with your code unless it indicates a problem that is tied up to the lack of assignment. Null, NaN, and empty values all indicate the lack of a value rather than the lack of assignment, which is usually the desired behavior.

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!