Default operator strawman - ||| rather than ??
Tab Atkins Jr.
jackalmage at gmail.com
Tue Jun 12 13:56:18 PDT 2012
On Tue, Jun 12, 2012 at 1:37 PM, Peter van der Zee <ecma at qfox.nl> wrote:
> On Tue, Jun 12, 2012 at 5:29 PM, T.J. Crowder <tj at crowdersoftware.com> wrote:
>> In the current default operator strawman, the operator is ??, e.g.:
>> a = b ?? 5;
>> is shorthand for
>> a = b !== undefined ? b : 5;
> I missed this discussion. What validates the introduction of this
> syntax over the equally simple and already possible `a = b || 5`? Is
> the comparison to `undefined` (and why not `==null` as well??) really
> worth the introduction (and subsequent loss of future usage) of the
> double question mark? Whatever it's usual name is (double wat?).
If b is falsey (0, false, null), it'll use the 5, even though you only
intended it to be used when b is undefined.
"undefined" is special-cased here because it's an extremely common
value to check against. It's used when an argument isn't supplied, or
when you try to pull a non-existent property off of an object.
More information about the es-discuss