You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the most important changes made by the introduction of strict mode was to throw errors in several cases where JS assignments used to silently fail.
This proposal seems to be re-introducing silent assignment failures.
This is especially true if the intention is to allow any form of optional chain on the LHS so long as it ends with ?.prop or ?.[expr]. In that case even when you determine that a silent failure has occurred, you don't know which value was undefined.
The text was updated successfully, but these errors were encountered:
All the cases that were made to throw with strict mode would still throw with ?. (in strict mode):
a?.b = c throws if a is not declared
a?.b = c throws if b is a read-only property
Which is similar to how delete a?.b already throws in strict mode if b is a non-configurable property.
Strict mode was about avoid suppressing implicit failures, while in this case the potential failures are explicitly marked. The language already has conditional assignment operators (??=, ||= and &&=) that silently avoid assigning values. Their behavior is unsurprising because they are explicitly marked, similarly to how the optional behavior of this proposal is explicitly marked via ?.
In that case even when you determine that a silent failure has occurred, you don't know which value was undefined.
This is a property of optional chaining in general, not specific to using it in assignment positions. In console.log(a.b?.c?.d) even if you determine that the result is undefined you don't know which one of the properties was undefined.
One of the most important changes made by the introduction of strict mode was to throw errors in several cases where JS assignments used to silently fail.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
This proposal seems to be re-introducing silent assignment failures.
This is especially true if the intention is to allow any form of optional chain on the LHS so long as it ends with
?.prop
or?.[expr]
. In that case even when you determine that a silent failure has occurred, you don't know which value wasundefined
.The text was updated successfully, but these errors were encountered: