JavaScript eval() Function
Example
Evaluate/Execute JavaScript code/expressions:
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 of res will be:
200
4
27
Try it yourself »
Definition and Usage
The eval() function evaluates or executes an argument.
If the argument is an expression, eval() evaluates the expression. If the argument is one or more JavaScript statements, eval() executes the statements.
Browser Support
Function | |||||
---|---|---|---|---|---|
eval() | Yes | Yes | Yes | Yes | Yes |
Syntax
eval(string)
Parameter Values
Parameter | Description |
---|---|
string | A JavaScript expression, variable, statement, or sequence of statements |
Technical Details
JavaScript Version: | 1.0 |
---|
JavaScript Global Functions