Home > Web Front-end > JS Tutorial > body text

How to use eval function

不言
Release: 2019-01-29 14:52:46
Original
15879 people have browsed it

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)
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!