Reputation: 399
As the spec states (yes, 5.1, that's intentional):
AssignmentExpression :
ConditionalExpression
LeftHandSideExpression = AssignmentExpression
LeftHandSideExpression AssignmentOperator AssignmentExpression
Based on this definition, I don't understand how a simple foo = 42
assignment is valid.
My understanding is, that foo =
should always be followed by either a ConditionalExpression
or essentially another assignment, but in that case, how will the production terminate if I don't use a ConditionalExpression
? All further AssignmentExpression
rules require either a ConditionalExpression
or another AssignmentExpression
.
What am I missing here?
Upvotes: 4
Views: 86
Reputation: 664599
The expression after the =
operator must always be an AssignmentExpression. This AssignmentExpression will often consist not of another assignment, but a plain ConditionalExpression, which in turn will consist of a simpler expression that might contain an operator or not, all the way down through the operator precedence hierarchy to the Literal that your number 123
forms.
Upvotes: 1