In JavaScript, declare variable format: var (keyword) + variable name (identifier).
Mode 1
var test;
var test = 5;
Note that the sentence cannot be contained within a function, otherwise it is a local variable. This is the first way to declare a global variable.
Mode 2
Test = 5;
No var is used to assign a value directly to the identifier test, which implicitly declares the global variable test. Even though the statement is within a function, when the function is executed, test becomes a global variable.
Mode 3
Window.test;
Window.test = 5;
This approach is often used when an anonymous function is executed to expose some functions to the global. As the last sentence in JQuery1.5
Window.jquery = window.$ = JQuery;
Directly in the JS file to write the Var variable =xxx on the line, so all JS can get this variable, or directly write window.xxxx=xxx
JavaScript declares global variables three ways of difference