JavaScript eval () function
Definition and Usage
eval () function calculates the JavaScript string, and use it as the script code to execute.
If the argument is an expression, eval () function to execute expressions. If the argument is Javascript statements, eval () statement will execute Javascript.
grammar
eval(string)
参数 | 描述 |
---|---|
string | 必需。要计算的字符串,其中含有要计算的 JavaScript 表达式或要执行的语句。 |
Browser Support
All major browsers support eval () function
Examples
Examples
Execute JavaScript code or expression:
<script>
eval("x=10;y=20;document.write(x*y)");
document.write("<br>" + eval("2+2"));
document.write("<br>" + eval(x+17));
</script>
eval("x=10;y=20;document.write(x*y)");
document.write("<br>" + eval("2+2"));
document.write("<br>" + eval(x+17));
</script>
Examples of the above output:
200
4
27
4
27
try it"
JavaScript Global Functions