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.
- Još 8 drugih odgovora
Novi razgovor -
-
- Još 3 druga odgovora
Novi razgovor -
-
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
Kraj razgovora
Novi razgovor -
-
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.
- Još 2 druga odgovora
Novi razgovor -
-
-
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.
Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
-
-
Mirip PHP
Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.
Nullish coalescing syntax is coming to JavaScript!
This feature enables safer default expressions.