eval() (Function/global)

Execute some script source passed as an argument.

Availability:

ECMAScript edition - 2
JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Opera - 3.0
Property/method value type:Depends on the script source passed as an argument
JavaScript syntax:-eval(aSourceText)
Argument list:aSourceTextA string value containing some syntactically correct script source code

When the eval() function is called, it expects a string to be passed to it as its single argument value. The contents of that string should be syntactically correct executable script source text.

The script code gets executed and any result it generates is returned. That value must be explicitly returned, otherwise the result will be undefined.

Warnings:

Example code:

   // Create some script source

   var scriptCode = "c = a * b";

   var a = 5;

   var b = 10;

   var c = 2;

   document.write(c);

   document.write("<BR>");

   eval(scriptCode);

   document.write(c);

See also:Eval code, Function code, Function property, function( ... ) ..., Global object, JSObject.eval(), Object.eval(), Window.setInterval(), Window.setTimeout()

Property attributes:

DontEnum.

Cross-references:

ECMA 262 edition 2 - section - 10.1.2

ECMA 262 edition 2 - section - 15.1.2.1

ECMA 262 edition 3 - section - 10.1.2

ECMA 262 edition 3 - section - 15.1.2.1

Wrox Instant JavaScript - page - 28