News for hackers. Stuff that matters.
Re:Ask HN: Do You Use Enum for Yes, No, Unset? by gnabgib on Friday June 17, 2022 @06:08PM (#31785039)
And it's terrible because there's both `null` and `undefined` which have largely the same meaning but aren't equal. Depending on what you're interacting with, you may need to use one over the other or coerce. Especially common with developers from other languages who don't even know of the gotcha
Re:Ask HN: Do You Use Enum for Yes, No, Unset? by 8note on Friday June 17, 2022 @10:20PM (#31786781)
I've never found a use for null where undefined wouldn't be simpler to use. Especially with the ?? Operator to set defaults along the way
Re:Ask HN: Do You Use Enum for Yes, No, Unset? by j1elo on Saturday June 18, 2022 @04:41AM (#31788229)
This is a very curious and fun way to put it:

https://stackoverflow.com/a/57249968

In essence, `undefined` is non-existence. And `null` is existence with a non- (or "invalid", or "unknown") value.

Although using them like that depends on the needs of the application. If "invalid" or "unknown" was an expected user choice, I would still rather encode it as an enum better than a nullable boolean, as mentioned in my comment above.