JavaScript Evaluating JavaScript Evaluate a string of JavaScript statements

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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.



Got any JavaScript Question?