Difference between the || coalescing syntax?
-
-
-
null-ish is different from falsey. Only `null` or `undefined` is considered null-ish. So for example: const x = "" || "default"; // x = "default" const x = "" ?? "default"; // x = "" The example in the tweet is not really showing of what’s new here.
- 8 more replies
New conversation -
-
- 3 more replies
New conversation -
-
really? ...horror story. I want const a = b ?? c // to be equivalent to const a = b !== undefined ? b : c I use `null` as an explicit "empty value", while I'm using `undefined` as something doesnt exist or was never initialized... That's semantically different
End of conversation
New conversation -
-
You can also do this with ES3, replace `??` with `||`. If this is the canonical example for this feature, then I don't really see the value. Please consider not breaking backwards compatibility for things that already work fine.
-
What is breaking backwards compatibility here? `??` previously threw a SyntaxError exception.
- 2 more replies
New conversation -
-
-
Since nullish coalescing is similar to ||, it's totally reasonable that it would have exactly same precedence. 'a || b && c' may also violate expectations, but once one learns that 2+2*2=6, it's fine.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Mirip PHP
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
Nullish coalescing syntax is coming to JavaScript!
This feature enables safer default expressions.