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<
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.