Easy question. Does exist something like php's ?? in javascript?
In php you can do condition ?? statement2
which is the same as condition? condition : statement2.
Is there something like that in javascript?
I would use the logical or operator (||)
console.log("true value" || "other")
console.log(false || "other")
This works because (source):
expr1 || expr2Returnsexpr1if it can be converted to true; otherwise, returnsexpr2
||worked. Thanks??is called the null coalescing operator. The linked question is "Null coalescing operator Javascript." It's literally the same question, and the accepted answer there answers OP's question exactly.