1let str = "12/5*9+9.4*2"
2
3let res1 = eval(str)
4console.log('res1:', res1)
5
6let res2 = (new Function('return '+str)())
7console.log('res2:', res2)
1var theInstructions = "alert('Hello World'); var x = 100";
2
3var F=new Function (theInstructions);
4
5return(F());
1The eval() function evaluates JavaScript code represented as a string.
2
3console.log(eval('2 + 2'));
4// expected output: 4
5
6console.log(eval(new String('2 + 2')));
7// expected output: 2 + 2
8
9console.log(eval('2 + 2') === eval('4'));
10// expected output: true
11
12console.log(eval('2 + 2') === eval(new String('2 + 2')));
13// expected output: false
14
15
1eval() -> is able to evalute the things inside it , like eval(a+b+c) , wher a=3,b=4,c=4 , so eval(a+b+c) = 11