Variables declared with VAR are generally local variables.
function Test () { var temp = "DSD"; #局部 Console.log (temp);} Test () /*DSD*/console.log ( temp)/* cannot output, variable is declaration */*uncaught referenceerror:temp is not defined* /
Variables declared in a function that do not use Var are global variables
function Test () { = "DSD"; #全局 Console.log (temp);} Test () /*DSD*/console.log ( temp)/*DSD */
or use window to load the data into the current window, or you can implement a global
function Test () { window[' temp ']= "DSD"; Console.log (window['temp');} Test () /*DSD*/console.log (window['Temp ']/ *DSD* /
Nature: Variables declared above are not used by Var, which is equivalent to window. Variable or window[' variable ']
function Test () {v="Dsadas"Console.log (v)}test ()/*Dsadas*/Console.log (v)/*Dsadas*/Console.log (WINDOW.V)/*Dsadas*/Console.log (window['v'])/*Dsadas*/
The global variables in JS