Object.eval()

JavaScript 1.1+, Jscript 3.0+ Nav3+, NES2+, IE4+ Syntax

							object.eval(string)

Description

The eval() method of the Object object evaluates a string of JavaScript code in reference to this object.

Example

Listing 6.193 shows how the eval() method is used. Two variables are declared and set. A statement multiplying the two variables together is passed to the eval() method to be evaluated.

Listing 6.193 Example of eval() Method
<html>
<body>

<script language="JavaScript">
<!––Hide

var x = 9;
var y = 8;

document.write("The result of x * y is: " + eval(x * y));
// End Hide ––>
</script>

</body>
</html>
							
							
						

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.