Sunday, 10 July 2011

JavaScript eval() Function


·      The eval() function evaluates or executes an argument.
·      If the argument is an expression, eval() evaluates the expression. If the argument is one or more JavaScript statements, eval() executes the statements.
·      The eval() function is supported in all major browsers.

Syntax: eval(string)
string: A JavaScript expression, variable, statement, or sequence of statements.

Ex:
<script type="text/javascript">
          eval("x=10;y=5;document.write(x*y)");
          document.write("<br />" + eval("2+3"));
          document.write("<br />" + eval(x+15));
</script>
Output:
50
5
25

No comments:

Post a Comment