Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use eval in javascript

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to use eval in javascript, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The eval function in javascript is used to evaluate a string and executes the JavaScript code in it. The syntax for this function is "eval (string)", and the parameter string represents the string to be evaluated.

This article operating environment: windows7 system, javascript1.8.5 version, DELL G3 computer.

The usage of eval in javascript

The eval () function evaluates a string and executes the JavaScript code in it.

Grammar

Eval (string)

The parameter string must be the string to evaluate that contains the JavaScript expression to evaluate or the statement to execute.

Return value: the value obtained by calculating the string, if any.

Description

This method only accepts the original string as a parameter, and if the string parameter is not the original string, then the method will return without any change. So do not pass a String object as an argument to the eval () function.

If you try to override the eval property or assign the eval () method to another property and call it through that property, the ECMAScript implementation allows an EvalError exception to be thrown.

Throw out

If there is no legal expression and statement in the parameter, a SyntaxError exception is thrown.

If eval () is called illegally, an EvalError exception is thrown.

If the Javascript code passed to eval () generates an exception, eval () passes the exception to the caller.

Tip: although eval () is very powerful, it is rarely used in practice.

Example

In this example, we will apply eval () on several strings and look at the result returned:

Eval ("Xerox 10 / 20; [xss_clean] (Xeroy)") [xss_clean] (eval ("2x / 2")) var x = 10 [XSS _ clean] (eval (x / 17)

Output:

More than 200427 are all the contents of this article entitled "how to use eval in javascript". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report