en.javascript.info icon indicating copy to clipboard operation
en.javascript.info copied to clipboard

Misleading Explanation About Comma Operator Precedence

Open mones-cse opened this issue 1 year ago • 2 comments

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!

mones-cse avatar Feb 11 '24 12:02 mones-cse

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

joaquinelio avatar Feb 11 '24 15:02 joaquinelio

@joaquinelio thanks

mones-cse avatar Feb 23 '24 03:02 mones-cse