Home  >  Article  >  Web Front-end  >  What is the use of eval function in js

What is the use of eval function in js

青灯夜游
青灯夜游Original
2019-06-01 10:40:1414222browse

What is the use of eval function in js

The eval() function is used to calculate a JavaScript string and execute it as script code. If the argument is an expression, the eval() function will execute the expression. If the argument is a Javascript statement, eval() will execute the Javascript statement.

Syntax

eval(string)

Parameters:

● string: required. A string to evaluate that contains a JavaScript expression to evaluate or a statement to execute.

Description: All major browsers support the eval() function

Example:

<script>
eval("x=10;y=20;console.log(x*y)");
console.log(eval("2+2"));
console.log(eval("x+17"));
</script>

Output:

200
4
27

What is the use of eval function in js

The above is the detailed content of What is the use of eval function in js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn