Js eval function usage, conversion between js objects and strings., evaljs

Source: Internet
Author: User
Tags javascript eval

Js eval function usage, conversion between js objects and strings., evaljs

The js eval function is used to convert js objects and strings.


JavaScript eval () function JavaScript global function Definition and usage

The eval () function calculates the JavaScript string and runs it as script code.

If the parameter is an expression, the eval () function executes the expression. If the parameter is a Javascript statement, eval () executes the Javascript statement.

Syntax eval ( String)
Parameters Description
String Required. The string to be calculated, which contains the JavaScript expression to be calculated or the statement to be executed.

<! DOCTYPE html> <body> <script> var te = new Object (); te. a = 'fff'; te. B = 100; eval ("x = 10; y = 20; document. write (x * y) "); document. write ("<br>" + eval ("2 + 2"); document. write ("<br>" + eval (x + 17); var str = JSON. stringify (te); alert (str); eval ('He ('+ str +'); function he (va) {var str = JSON. stringify (va); alert (str); var obj = JSON. parse (str); // converts a json string to an alert (obj);} </script> </body> 



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.