DEV Community

Discussion on: You don't need null

 
loucyx profile image
Lou Cyx
  1. If the API fails, you should handle that in other ways (response headers and proper error handling), if the API responded with the wrong body, that will be a problem either if you use null or undefined, so I still don't see much value for null in this scenario. If a value can either come or not, then you can define it as optional (meaning Type | undefined), and in the front end you can just do value ?? "default value" or if (value === undefined) { throw // ... } or whatever πŸ˜„
  2. You should take a look at optional chaining and nullish coalescing, saying "it's bad when you try to use an undefined variable" feels like you might not be aware of this operators, but long story short, it's no longer bad. You can even "call" undefined πŸŽ‰
 
martinpham profile image
Martin Pham
  1. Of course you can handle it anyway, but how you know if the value is missing (an error), or if the value is not set?
  2. I was saying that about other languages, not js

Some comments have been hidden by the post's author - find out more