window.variableName

前端 未结 6 1818
梦如初夏
梦如初夏 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 07:05

    window.variableName means that the variable is being declared at the global scope. This means any JS code will have access to this variable. Using window. is not necessary but is frequently used as a convention to denote that a variable is global.

    Globals are generally to be avoided. You should define variables within the scope of functions.

提交回复
热议问题