Description
The eval() function is used to evaluate and/or execute a string of JavaScript code.
This function has the form:
eval(string)
Parameter | Description |
---|---|
string | (optional) The string to be evaluated/executed |
Examples
The following example shows the basic use of this method.
<script>
var x = 10;
var y = 5;
document.write(eval("2+2"));
document.write("<br />");
document.write(eval(x*y));
</script>
This produces the following result:
Browser Support
Firefox | IE | Chrome | Opera | Safari |
---|---|---|---|---|