Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading Explanation About Comma Operator Precedence #3667

Open
mones-cse opened this issue Feb 11, 2024 · 2 comments
Open

Misleading Explanation About Comma Operator Precedence #3667

mones-cse opened this issue Feb 11, 2024 · 2 comments

Comments

@mones-cse
Copy link

mones-cse commented Feb 11, 2024

Hi there,

I've come across a section in the documentation (https://javascript.info/operators#comma) that explains the precedence of the comma operator.
image

However, it seems to have an error in its explanation. The example provided suggests that a = 1 + 2, 3 + 4 should result in a being assigned the value 3, whereas in reality, it correctly returns 7.
image

I believe this discrepancy could lead to confusion among learners, and the explanation might need clarification to reflect the actual behavior of the comma operator. Thank you for your attention to this matter!

@joaquinelio
Copy link
Member

joaquinelio commented Feb 11, 2024

Tricky.
What's returning is the result of the last operation,
But a keeps the 3 and doesn't change

Try
>a0

Or try

> 1 + 2
And
>  a = 1+2

to understand the difference and why it showed only the 7

@mones-cse
Copy link
Author

@joaquinelio thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants