The eval (string) function computes a string and executes the JavaScript code in it.
return value
The value, if any, obtained by calculating the string.
Description
The method accepts only the original string as a parameter, and if the string argument is not the original string, the method returns without any changes. Therefore, do not pass a String object as an argument for the eval () function.
If you attempt to overwrite the Eval attribute or assign the eval () method to another property and call it through this property, the ECMAScript implementation allows a Evalerror exception to be thrown.
Thrown
Throws an SyntaxError exception if there are no valid expressions and statements in the argument.
If Eval () is invoked illegally, a Evalerror exception is thrown.
If the Javascript code passed to eval () generates an exception, eval () passes the exception to the caller.
Tips and comments
Tip: Although the eval () is very powerful, it is not much used in practice.
Example:
Output:
200
4
24