FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Clarify precedence of comma operator in article and add missing "let"… by Lk-ux · Pull Request #3974 · javascript-tutorial/en.javascript.info · GitHub

Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .md  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 2 additions & 2 deletions 1-js/02-first-steps/08-operators/article.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ alert( a ); // 7 (the result of 3 + 4)
Here, the first expression `1 + 2` is evaluated and its result is thrown away. Then, `3 + 4` is evaluated and returned as the result.

```smart header="Comma has a very low precedence"
Please note that the comma operator has very low precedence, lower than `=`, so parentheses are important in the example above.
Please note that the comma operator has the lowest precedence, lower than `=`, so parentheses are important in the example above.

Without them: `a = 1 + 2, 3 + 4` evaluates `+` first, summing the numbers into `a = 3, 7`, then the assignment operator `=` assigns `a = 3`, and the rest is ignored. It's like `(a = 1 + 2), 3 + 4`.
```
Expand All @@ -472,7 +472,7 @@ For example:

```js
// three operations in one line
for (*!*a = 1, b = 3, c = a * b*/!*; a < 10; a++) {
for (*!*let a = 1, b = 3, c = a * b*/!*; a < 10; a++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Keep the loop initializer as a comma expression

Adding let changes this initializer from a comma expression into a lexical declaration containing three declarators, where the commas are separators rather than instances of the comma operator. Consequently, the section's final example no longer demonstrates the operator it claims frameworks use; declare the variables separately and retain the assignment expression in the initializer, or otherwise use an actual comma expression here.

Useful? React with 👍 / 👎.

...
}
```
Expand Down

Back | FazBrowse Home | New Git URL