JavaScript Evaluating JavaScript Evaluation and Math

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

You can set a variable to something with the eval() function by using something similar to the below code:

var x = 10;
var y = 20;
var a = eval("x * y") + "<br>";
var b = eval("2 + 2") + "<br>";
var c = eval("x + 17") + "<br>";

var res = a + b + c;

The result, stored in the variable res, will be:

200
4
27

The use of eval is strongly discouraged. See the Remarks section for details.



Got any JavaScript Question?