Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
eval Method
Collapse the table of content
Expand the table of content

eval Method (Windows Scripting - JScript)

 

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);

Change History

Date

History

Reason

January 2010

Modified example.

Information enhancement.

Show:
© 2015 Microsoft