Home >Web Front-end >JS Tutorial >How to use eval function
The eval() function in How to use eval function is a function attribute of the global object. The parameter of the eval() function is a string. If the string represents an expression, then eval() calculates the expression. If the argument represents one or more How to use eval function statements, eval() evaluates the statements.
Let’s look at the basic syntax of the eval function:
eval(string)
String: A string representing a How to use eval function expression, statement, or sequence of statements. Expressions can include variables and properties of existing objects.
Return value: Use the eval() function to return the value of the given code; if the value is empty, undefined is returned.
Let’s look at a specific example
The code is as follows
<!DOCTYPE html> <html> <head> <title></title> </head> <script> function func() { var a = 2; var b = 6; var value = eval(new String(a + b)); document.write(value); } func(); </script> </body> </html>
The running result is: 8
This article It’s all over here. For more exciting content, you can pay attention to the relevant column tutorials on the PHP Chinese website! ! !
The above is the detailed content of How to use eval function. For more information, please follow other related articles on the PHP Chinese website!