JavaScript eval()Function

函数参考手册JavaScript Global Functions

Definition and Usage

The eval() function evaluates a JavaScript string and executes it 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

eval(string)

Parameters Description
string Required. The string to be evaluated, containing the JavaScript expression to be evaluated or the statement to be executed.


Browser Support

Function
eval() Yes Yes Yes Yes Yes

Example

Example

Execute 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

Try it yourself »


函数参考手册JavaScript Global Functions Other extensions