Your preferred style(s) for checking for nullish in JavaScript:

@wallhackio Why would you ever write any of the above two options instead of if (!x)? Asking as a C programmer. Are there any situations where these do different things?

@vaporeon_ there are non-nullish values that are coerced to false. or x could be false itself. That means the following values would also be treated as nullish:

false
""
0
-0
0n
NaN

@vaporeon_ might not be an issue if you have runtime type checking before the query, or if your JavaScript is compiled/transpiled from TypeScript, or if you have extensive confidence in your software testing

Follow

@wallhackio @vaporeon_ or if you lint your js with typescript, the only actually good use fur typescript

@wallhackio @vaporeon_ fuck the typescript compiler i just wanna run my actual js directly

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.