JavaScript tutorial:
eval method

 

Applies to: Global Object

Evaluates JavaScript code and executes it.

Syntax

eval(codestring)

The codestring argument is a String object that contains valid JavaScript code. This string is parsed by the JavaScript parser and executed.

Example

The eval function allows dynamic execution of JavaScript source code. For example, the following code creates a new variable mydate that contains a Date object:

eval("var mydate = new Date();");

The code passed to the eval method is executed in the same context as the call to the eval method.

  To run the code above, paste it into JavaScript Editor, and click the Execute button

See also: String Object