Home > Web Front-end > JS Tutorial > What are the ways to declare a function?

What are the ways to declare a function?

一个新手
Release: 2017-09-18 10:32:00
Original
3704 people have browsed it

There are three ways to declare a function

1. Ordinary declaration method:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>三种声明函数的方式</title>
</head>
<body>
	<script>
		function func(m,n){
			alert(m+n);
		}
		func(7,8);
	</script>
</body></html>
Copy after login

Test result:


##2. Use variables Declaration function:

##

	var func=function(m,n){
			alert(m+n);
		}
		func(9,4);
Copy after login
Test effect:



3. Use constructor declaration:

##

var func=new Function(&#39;m&#39;,&#39;n&#39;,&#39;alert(m+n)&#39;);
		func(1,7);
Copy after login
Test effect:


The above is the detailed content of What are the ways to declare a 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