DEV Community

Discussion on: Replace null with ES6 Symbols

robinpokorny profile image
Robin Pokorny Author

Hey! I'm not sure if undefined is better than null, in most cases there is not much difference. The. benefit of null or a Symbol is that it is more explicit. For me, undefined is the value the interpreter, null or Symbols are for users (this is not how it works, it's how I look at it).
Anyway, nullable for me means either undefined or null and the biggest issue with it remains: there is only one (well, two :D) and you cannot control how others use it.

lukeshiru profile image

From my point of view there is a bunch of reasons to prefer undefined over null:

  • For consistency sake, is better to just have one "nullable" value, not two.
  • undefined is the default value for variables without a value, arguments that aren't set, missing properties in an object, and so on.
  • If I do typeof it isn't bugged as null, it actually returns "undefined".
  • I still can use ?. and ??.
  • I honesty don't see the value in differentiate between a value that isn't defined that one that I intentionally left blank, when we have to deal with both the same way.
  • Responses are more lightweight:
{ foo: "foo", bar: null }
// vs
{ foo: "foo" }
Enter fullscreen mode Exit fullscreen mode

Again, don't take this the wrong way, I'm not saying "this is the way", I'm just listing the reasoning behind my preference, and that's why I commented in the first place, because I wanted to get your reasoning behind preferring a symbol over undefined mainly (null I get, because I also don't use it at all).