eval
eval(parse) parse: It contains the parameter string. We know that executing javascript will compile and execute.
Change the value of the global variable:
var x = ; //The defined global variable alert(x);//var g = eval("x="); //eval will parse xalert(x);//Referring to eval in the global scope, change the value of the global scope, and not change the value of the local scope
var g = eval; //Global reference evalvar x = "global";//Define global variable(function f() {var x = "local";g("x+='changed'");alert(x);//Local variable local})();//IIFE Execute the expression alert(x);//The value of the global variable globalchangedReferences to change the value of local variables within the local scope, and do not change the value of global variables
var g = eval; //Global reference evalvar x = "global";//Define global variable(function f() {var x = "local";eval("x+='changed'");alert(x);//Local variable localchanged})();//IIFE Execute the expression alert(x);//The value of the global variable globalSummary
The execution of eval will determine whether the changed variable is local or global according to the context. Therefore, the key to using the eval function is to see clearly the scope of the reference eval!
The above is the relevant knowledge about the use of JavaScript (V) eval introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!