What is eval() in JavaScript?
In JavaScript, eval is something of a hybrid between an expression evaluator and a statement executor. It returns the result of the last expression evaluated (all statements are expressions in both Javascript & ActionScript), and allows the final semicolon to be left off.
Example as a statement executor:
<head>
<script type="text/javascript">
fo = 2;
eval('fo = fo + 2;alert(fo);');
</script>
</head>
<body onload="eval()">
</body>
Example as an expression evaluator:
<head>
<script type="text/javascript">
fo = 2;
alert(eval('fo + 2'));
</script>
</head>
<body onload="eval()">
</body>