javascript-tutorial / en.javascript.info

Modern JavaScript Tutorial
https://javascript.info
Other
23.05k stars 3.82k forks source link

Misleading Explanation About Comma Operator Precedence #3667

Open mones-cse opened 5 months ago

mones-cse commented 5 months ago

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 commented 5 months ago

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 commented 4 months ago

@joaquinelio thanks