Export (0) Print
Expand All
Expand Minimize

eval Method (Windows Scripting - JScript)

Updated: January 2010

Evaluates JScript code and executes it.

                      eval( 
                      codeString 
                      )

codeString

Required. A String value that contains valid JScript code.

The eval method enables dynamic execution of JScript source code.

The codeString string is parsed by the JScript parser and executed.

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

Whenever possible, use the JSON.parse Method to de-serialize JavaScript Object Notation (JSON) text. The parse method is more secure and executes faster than the eval method.

The following code initializes the variable myDate to a test date.

var dateFn = "Date(1971,3,8)";
var myDate;
eval("myDate = new " + dateFn + ";");

document.write(myDate);

Date

History

Reason

January 2010

Modified example.

Information enhancement.

Community Additions

ADD
Show:
© 2014 Microsoft