0

we use an assignment operator = in order to assign a value to a variable, so the value assigned is an operand but the variable itself counts as another one?? if not is only a unary operator, that makes sense for me, but if not it's binary, but why? why the var is considered an operand in case that this will be true?

4
  • 4
    The left side is considered an operand for parsing purposes. But it acts different from all other operands, because it's a reference to a location that can be updated, not a value. In compiler terminology it's an L-value rather than an R-value. Commented Mar 7, 2023 at 20:34
  • 1
    Treating it as a binary operator means no special handling is required in a recursive descent parser with operator precedence. Commented Mar 7, 2023 at 20:36
  • The ECMAScript specification does not call the left hand side an operand, but surely you could. It's an operand whose current value plays no role (like with the comma operator), and the assignment is a side effect, just like the unary operator ++ has a side effect. Moreover, there are other assignment operators, which do use the current value of the lefthand side variable, so they really cannot be seen other than binary (like +=) Commented Mar 7, 2023 at 20:37
  • I'm having trouble parsing this: "if not is only a unary operator". It's a binary operator because the left operand is required. You can't write just = 1, you have to write something = 1. Commented Mar 7, 2023 at 21:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.