JavaScript function eval ()

Source: Internet
Author: User

The function of the eval () function is to execute the string in the form of a script
For example:

<script type= "Text/javascript" >  var str = "Var name= ' Zhang San '";  eval (str);  document.write (name);  Output Zhang San </script>



Specific application scenarios:
Pass the server-side string parameters, according to the JS script execution
For example: a string such as "[10,20,30]" is passed by the server and can be used to parse the string into an array object using eval
<script type= "Text/javascript" >  var str = "[10,20,30]";  This is the string passed from the server to  var array = eval (str);   Parse the Array object and assign the value to the arrays variable for  (Var i=0;i<array.length;i++) {    document.write (array[i]+ "&nbsp;");  }  Output result (30</script>)

JavaScript function eval ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.