var x=5; var y=eval('x+2'); alert(y); //7 alert('z'); //z
A common example, get the current value of a variable.
var x=5; function incr(x) { x = x + 10; alert(eval('x')); } incr(x); //15
In above example, if we want to evaluate
var x=5; function incr(x) { x = x + 10; alert(window.eval('x')); } incr(x); //5