Skip to content

Instantly share code, notes, and snippets.

@samarpanda
Created July 22, 2014 08:58
Show Gist options
  • Select an option

  • Save samarpanda/e39e03aad9fda3d40aa5 to your computer and use it in GitHub Desktop.

Select an option

Save samarpanda/e39e03aad9fda3d40aa5 to your computer and use it in GitHub Desktop.
Difference between using eval and new Function.
/**
* test1();
* Output: 22
*/
function test1(){
var a = 11;
eval('(a = 22)');
alert(a);
}
/**
* test2();
* Output: 11
*/
function test2(){
var a = 11;
new Function('return (a=22);')();
alert(a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment