Home Javascript JavaScript method eval()



JavaScript method eval()
Posted on: April 3, 2006 at 12:00 AM
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

     

Related Tags for JavaScript method eval():


More Tutorials from this section

Ask Questions?    Discuss: JavaScript method eval()  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

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.