Easy Tutorial
❮ Prop Number Readonly Jsref Isnan ❯

JavaScript eval() Function


Definition and Usage

The eval() function evaluates JavaScript strings and executes them as script code.

If the argument is an expression, the eval() function will execute the expression. If the argument is JavaScript statements, eval() will execute the JavaScript statements.

Syntax

Parameter Description
string Required. The string to be evaluated, containing the JavaScript expression or statements to be executed.

Browser Support

Function
eval() Yes Yes Yes Yes Yes

Example

Executing JavaScript code or expressions:

eval("x=10;y=20;document.write(x*y)");
document.write("<br>" + eval("2+2"));
document.write("<br>" + eval(x+17));

The above example outputs:

200
4
27

❮ Prop Number Readonly Jsref Isnan ❯