Home Javascript JavaScript method eval()

Related Tutorials


 
 

Share on Google+Share on Google+

JavaScript method eval()

Advertisement
This section illustrates you the use of JavaScript method eval(). This function evaluates the string passed into the method and executes it.

JavaScript method eval()

     

This section illustrates you the use of JavaScript method eval(). This function evaluates the string passed into the method and executes it.

Its syntax is:

eval(codestring)

The codestring argument is a String object that contains valid JavaScript code. JavaScript parser parses and executes the string. In case if there is no argument, eval() method returns "undefined". In the given example, we defined different JavaScript statements and expressions to use the method eval().

 

 

Here is the code:

<html>
<script type="text/javascript">
var x=15;
var name = 'Angelina';
document.write(eval('"Welcome " + name;'));
document.write("<br />");
document.write("The sum of two numbers is: "+eval(x+5));
document.write("<br />");
eval("x=25;y=35;document.write('The product of two numbers is:'+ x*y)");
document.write("<br />");
</script>
</html>

Output will be displayed as:

Download Source Code

     

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 3, 2006

Related Tutorials

Discuss: JavaScript method eval()  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com