Topic on Manual talk:Coding conventions/JavaScript

Short way to check for nullish inline?

4
Aaron Liu (talkcontribs)

something == null ? fallback : something is prohibited by the equality section and something ?? fallback is prohibited due to being too new. The next best way would be (typeof something === "undefined" || something === null) ? fallback : something, which is quite too much of a mouthful. Is there some shorter way I'm not aware of, or is this use case just too niche for the MediaWiki codebase?

Nardog (talkcontribs)

If you know the expected type you could do e.g. !something && something !== ''.

This post was hidden by Aaron Liu (history)
Aaron Liu (talkcontribs)

Ooh, that is smart. It stunned my brain for a minute but it is short and nice. THanks.

Reply to "Short way to check for nullish inline?"