Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 5, 2020 11:08 am GMT

How do you deal with null vs undefined?

I just recently started refactoring my large scale angular app to Typescript's strict mode. Dealing with lots of null checks the question arose again if I should prefer using undefined over null or vice versa. A couple of thoughts:

  1. Is using undefined for initially undefined values and using null whenever you want to unassign a value a good option?
  2. Using undefined everywhere simplifies things at first, but then there is JSON (only null available) and API responses. How to best deal with those?
  3. How to best deal with pre-checks for when you are reasonably confident that a value is not null, but it theoretically could be (e.g. angular @Inputs you always assign)? Do you prefer to typecast or do you use error checks?

I wonder how do you deal with the problem. Do you prefer one over the other? Do you use both? What's your take on it?


Original Link: https://dev.to/johannesjo/how-do-you-deal-with-null-vs-undefined-4899

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To