DEV Community

Discussion on: Replace null with ES6 Symbols

Collapse
lukeshiru profile image
LUKESHIRU

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).

Cheers!