window.variableName

前端 未结 6 1786
梦如初夏
梦如初夏 2020-11-28 06:45

I am going through some code and at the beginning of the script we have var emailID = email. Later on, the code refers to emailID by going window.emailID<

6条回答
  •  清酒与你
    2020-11-28 06:54

    Global variables in JavaScript are attached to the "global object", which in a browser environment is aliased to window object - this is why you can refer to a global variable either as variableName or window.variableName.

    It's also worth mentioning that using global variables in JavaScript is not considered good coding practice.

    Here's a good and very detailed explanation.

提交回复
热议问题