This article describes how to call a function, how to return a function, how to create an anonymous function, how to create a dynamic function in javascript, how to call a callback function, how to distinguish between a method and a function, how to create a js global function, and how to use a function., prototype attributes, high-level functions, it is very practical. for reference, the function is event-driven or reusable code block executed when it is called.
Jscript supports two types of functions: one is internal functions (such as eval (), and the other is self-created.
The variable declared inside the JavaScript function (using var) is a local variable, so it can only be accessed inside the function. (The scope of this variable is local ).
You can use local variables with the same name in different functions, because only functions that have declared the variable can recognize the variable.
Function call Method
1. Common call: functionName (actual parameter ...)
2. Call the function by pointing to the function variable:
Var myVar = function name;
MyVar (actual parameter ...);
Return Function
1. When the function does not return a specific value, the returned value is "undefined ".
2. When a function returns a value, the return value is returned.
We can use the return statement to return the function to the place where it is called.
When the return statement is used, the function stops execution and returns the specified value.
A function usually returns a unique value, which may be another function:
The Code is as follows: