Home >Web Front-end >JS Tutorial >How to use eval function

How to use eval function

不言
不言Original
2019-01-29 14:52:4615929browse

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.

How to use eval function

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!

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