var x = 5; var str = "if (x == 5) {console.log('z is 42'); z = 42;} else z = 0; "; console.log("z is ", eval(str));
The use of eval is strongly discouraged. See the Remarks section for details.
eval