From http://www.w3schools.com (Copyright Refsnes Data)

JavaScript eval() Function


Function Reference JavaScript Functions

Definition and Usage

The eval() function evaluates and/or executes a string of JavaScript code.

First, eval() determines if the argument is a valid string, then eval() parses the string looking for JavaScript code. If it finds any JavaScript code, it will be executed.

Syntax

eval(string)

Parameter Description
string Optional. The string to be evaluated/executed


Example

Example

Evaluate/Execute JavaScript code/expressions:

<script type="text/javascript">

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

</script>

The output of the code above will be:

200
4
27

Try it yourself »


Function Reference JavaScript Functions

From http://www.w3schools.com (Copyright Refsnes Data)