Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

Have Programming Question? Ask it here!
 
 
 


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


What is eval() in JavaScript?


Advertisement
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 Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com