Home > Article > Web Front-end > 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
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!