this post was submitted on 14 Aug 2025
119 points (96.9% liked)
Programmer Humor
38282 readers
92 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 6 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
The logic is fine. If you rename the variable to
isAdmin
, it makes perfect sense. Either they are an admin, or they are not an admin, or the state is unknown (here expressed asnull
). If you want to throw another JS-ism at this,undefined
could be assigned before the check has been made.I regularly use variables like this. If
users
isundefined
, I haven’t fetched them yet. If they’re a list, then fetching is complete. If they’renull
, then there was an error while fetching.The only flaw is that the console.log states that null means user is not logged in.
If there are three or more explicit states, you should not use a nullable bool, but some more explicit data structure, like enum.
For example, if the state comes from a db, the user could be successfully logged in, but somehow for a range of possible reasons this variable ends up as null and you'll have a hell of a time debugging, because the log will give you nonsense.
Good point.