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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With