DEV Community

loading...

Discussion on: Replace null with ES6 Symbols

Collapse
0916dhkim profile image
Donghyeon Kim

One potential problem I can see from this approach is that js symbols convert to true. Which means it can confuse people when used like this:

const None = Symbol(`None`);
if (None) console.log('Oopsie');
Enter fullscreen mode Exit fullscreen mode
Collapse
robinpokorny profile image
Robin Pokorny Author

Yeah, I see that point. However, with so many falsy values in JS, I would not use the same for null or undefined either.

const value: string | null | undefined = 

if (value) { /* a non-empty string – intention or oversight? */}

if (value == null) { /* a string */ }
Enter fullscreen mode Exit fullscreen mode

Maybe NaN is a better choice? :D

Collapse
0916dhkim profile image
Donghyeon Kim

Actually, I was caught off guard by empty strings a few times before. You have a good point.