Closed sealep closed 1 year ago
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment
Logical OR assignment short-circuits, meaning that `x ||= y` is equivalent to `x || (x = y)`;
has the same issue
Yep, these three pages share the same structure, and I have a script to check that. So whoever updates one of them will be reminded by me that the rest should be updated (or if the PR is merged by someone else ahead of me, I can send a followup)
Actually I think this should be mentioned on every single compound assignment page: x += y
is equivalent to x = x + y
except x
is only evaluated once, etc.
Hi @Josh-Cena, I would like to work on this issue.
I believe the fix is that the documentation should specify that x or whichever variable comes first is only run once, right?
On all compound assignment operator pages, there is a sentence like:
x += y
is equivalent tox = x + y
.meaning that
x &&= y
is equivalent to:x && (x = y);
Your job is to make it read:
x += y
is equivalent tox = x + y
, except that the expressionx
is only evaluated once.x && (x = y);
Except that the expression
x
is only evaluated once.
Hi @Josh-Cena, can I work on this issue??
No need to ask. If anyone wants to send a PR, please do it right away.
Personally, I think it is better to use x = x ?? y
format rather than x ?? ( x = y )
format, as it is better for reader to understand
@skyclouds2001 they mean different things. The paragraph below are exactly to illustrate why x = x ?? y
is NOT equivalent, because it performs assignment even when x is not nullish.
MDN URL
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND_assignment
What specific section or headline is this issue about?
Description
What information was incorrect, unhelpful, or incomplete?
Worth mentioning that x &&= y is equivalent to x && ( x = y ) except that x is only evaluated once.
What did you expect to see?
Elaboration that x is evaluated only once in x &&= y.
Do you have any supporting links, references, or citations?
Caveat that in x &&= y, x is evaluated only once, contrary to x && ( x = y ).
Do you have anything more you want to share?
No response
MDN metadata
Page report details
* Folder: `en-us/web/javascript/reference/operators/logical_and_assignment` * MDN URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND_assignment * GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/web/javascript/reference/operators/logical_and_assignment/index.md * Last commit: https://github.com/mdn/content/commit/f616cb604af851f77f8cd59368e94ee3e43a8838 * Document last modified: 2023-08-15T14:59:44.000Z