Eval
Eval (parse) Parse: Inside with the argument string, we know that executing JavaScript will compile execution,
to change the value of a global variable:
var x = 2; Defines the global variable alert (x),//2 var g = eval ("x=3"), and//eval resolves x alert (x) based on the current context ;//3
referencing eval at the global scope, changing the value of the global scope without changing the value of the local scope
var g = eval; Global reference eval var x = "global";//define global variable (function f () { var x = "local"; G ("x+= ' changed '"); alert (x);//local variable locally });//iife immediately executes the expression alert (x);//The value of the global variable globalchanged
Reference changes the value of a local variable within a local scope without changing the value of the global variable
var g = eval; Global reference eval var x = "global";//define global variable (function f () { var x = "local"; Eval ("x+= ' changed '"); alert (x);//local variable localchanged });//iife immediately executes an expression alert (x);//global variable Value
Summary
Eval execution will determine whether the variable variables are local or global depending on the context, so using the Eval function is the key to seeing the scope of the reference eval!
JavaScript work must Know (v) use of eval