Value returned by the assignment

前端 未结 5 1634
佛祖请我去吃肉
佛祖请我去吃肉 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 04:44

    When you write var x = 5; it declares x and initalizes its value to 5.

    This is a VariableStatement, it returns nothing,

    but x=5 is an expression that assigns 5 to x. as there is no x, JavaScript implicitly creates a global x in normal code

提交回复
热议问题