-
Notifications
You must be signed in to change notification settings - Fork 23
Clarify what happens for 'a ?? b' when 'a' is not defined #13
Comments
I would expect it to still throw a ReferenceError, and I'd also expect the let/const TDZ to apply. This isn't an error suppression operator, it's a null/undefined-based selection operator. |
It's not necessarily "error suppression" in this case. The |
My reading of the spec for both this operator and the optional chaining proposal is that they throw CoffeeScript chose to treat undeclared variables the same as |
I think "typeof is special" is a better situation than "some ops throw reference errors and some don't". |
In the case of I could imagine a crowd of coders demanding to be able to write: var global ??= window ?? self ?? Function('this')() but I think they are better served with better debuggability together with: var global = System.global and maybe: System.isBrowser ? window.foo : global.bar |
Closing, since this proposal is at stage 4. |
Today, if you write
a || b
whena
has not been defined you get a ReferenceError at runtime. You can test for this case usingtypeof a !== "undefined"
, which seems similar to the undefined check for??
. Is the intended behavior fora ?? b
to result inb
ifa
has not been defined, or will it still throw a ReferenceError?The text was updated successfully, but these errors were encountered: