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

What are the ways to declare a function?

一个新手
一个新手Original
2017-09-18 10:32:003668browse

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>

Test result:


##2. Use variables Declaration function:

##

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



3. Use constructor declaration:

##

var func=new Function(&#39;m&#39;,&#39;n&#39;,&#39;alert(m+n)&#39;);
		func(1,7);
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!

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