Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript eval() Function

JavaScript eval() Function

Function Reference 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 evaluates the expression. If the argument is a JavaScript statement, eval() executes the JavaScript statement.

Syntax

eval(

string

)

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

Browser support

function
eval() Yes Yes Yes Yes Yes

Example

Example

Execute JavaScript code or an expression:

eval

(

"

x=10;y=20;document.write(x*y)

"

)

;

document

.

write

(

"


"

eval

(

"

2+2

"

)

)

;

document

.

write

(

"


"

eval

(

x

17

)

)

;

The output of the above example is:

200

4

27

Try it »


Function Reference JavaScript Global Functions