This article mainly introduces the basic knowledge of JavaScript Functions. It has good reference value. Let's take a look at what is a function together with the small Editor below?
A function is a code segment that completes a function.
A function is a code segment that can be executed repeatedly.
Convenient function Management and Maintenance
Custom Functions
Use the function keyword
Function Name ([parameter,...]) {
Code segment;
Return value ;}
Note:
The function name must not contain special characters.
The function name should have a clear meaning
It is recommended that the function name follow the hump mark or underline method.
Function names are case sensitive
If the function name is repeated, overwriting is generated.
A function can have either a parameter or no parameter. Either a parameter or multiple parameters can exist.
The function adds the return value through return. If no return is returned, undefined is returned by default.
No function call or execution
Anonymous Functions
Function expressions can be stored in variables or used as a function.
Anonymous functions can be passed as parameters to other functions, and the receiver functions can complete some functions through the passed functions.
You can use anonymous functions to execute some one-time tasks.
Construct a Function through Function ()
Defined by built-in JavaScript Function Constructor (Function ()
var myFunction=new Function('a','b','return a+b');var myFunction=function(a,b){return a+b;};
Note:
The above two methods are equivalent.
Avoid using the new keyword whenever possible
Source code
Running result:
The above is all the content of this article. I hope this article will help you in your study or work, and I also hope to support PHP!
For more information about JavaScript Functions, see the Chinese PHP website!