Value returned by the assignment

前端 未结 5 1599
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 04:32

Why does the regular assignment statement (say, x = 5) return the value assigned (5 in this case), while the assignment combined with a variable d

5条回答
  •  自闭症患者
    2020-11-27 05:02

    That's because var x = 5; is a variable statement, not an expression.

    The behaviour of this statement is described in Section 12.2 of the ECMAScript Language Reference.

    1. Evaluate VariableDeclarationList.
    2. Return (normal, empty, empty).

    This is basically a void return value.

提交回复
热议问题