Home Answers Viewqa JavaScriptQuestions What is eval() in JavaScript?

 
 


samar
What is eval() in JavaScript?
1 Answer(s)      2 years and 7 months ago
Posted in : JavaScript Questions

What is eval() in JavaScript?

View Answers

November 10, 2010 at 12:13 PM


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>









Related Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.