Home > Article > Web Front-end > What are the ways to declare a function?
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('m','n','alert(m+n)'); 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!