An Interest In:
Web News this Week
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
July 5, 2020 11:08 am GMT
Original Link: https://dev.to/johannesjo/how-do-you-deal-with-null-vs-undefined-4899
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:
- Is using
undefined
for initially undefined values and usingnull
whenever you want to unassign a value a good option? - Using
undefined
everywhere simplifies things at first, but then there is JSON (onlynull
available) and API responses. How to best deal with those? - 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:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To