1.JS运算符:
2.eval函数:
(1).eval函数解释运行代码字符串,并产生一个值
eval("3+2"); //5
(2).全局eval:
var geval = eval;
var x = "global", y = "global";
function f() {
var x = "local";
eval("x += 'changed'");
return x;
}
function g() {
var y = "local";
geval("y += 'changed'");
return y;
}
function h() {
var z = "local";
geval("z += 'change'");
return z;
}
//localchanged global
console.log(f(), x);
// local globalchanged
console.log(g(), y);
//报错,z未定义
console.log(h());