Definition and usage: The
eval() function can calculate a string and execute the JavaScript code in it.
Syntax:
eval(string)
Parameter string:
Required. A string to evaluate, containing a JavaScript expression to evaluate or a statement to execute.
Return value:
The value obtained by calculating string (if any).
Note:
This method only accepts original strings as parameters. If the string parameter is not an original string, then the method will return without any changes.
So please do not pass String objects as parameters to the eval() function. ECMAScript implementations allow an EvalError exception to be thrown if an attempt is made to override the eval property or assign the eval() method to another property and call it through that property.
Exception:
If there are no legal expressions and statements in the parameters, 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() will pass the exception to the caller.
The above is the detailed content of What does eval mean in js. For more information, please follow other related articles on the PHP Chinese website!