There is the syntax
variable ? variable : something else, but can I somehow leave out the second variable?
It would be cool to have a syntax like variable ?: something else.
Does something like this exists?
Thanks
You can do it like variable ?? something else or variable || something else depending on what behaviour you want exactly
The nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand.
This can be contrasted with the logical OR (||) operator, which returns the right-hand side operand if the left operand is any falsy value, not only null or undefined. In other words, if you use || to provide some default value to another variable foo, you may encounter unexpected behaviors if you consider some falsy values as usable (e.g., '' or 0). See below for more examples.