Evaluation and Math
suggest changeYou 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;
res is the string "200<br>4<br>27<br>". Each + "<br>" converts the number to a string, so the parts are not added as numbers.
eval is strongly discouraged. See the remarks on eval.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents