A function is an event-driven or reusable block of code that executes when it is invoked. This article focuses on JS basic knowledge of the blind spot summary function.
Arguments object in a function
There is a arguments inside each function that returns all parameters accepted by the function
Note: The Argumens receives the argument
The following is a sum function written using the arguments attribute:
function Sumonsteroids () {
var I, res = 0;
var number_of_params = arguments.length;
for (I = 0; I < Number_of_params; i++) {
res = arguments[i];
return res;
Ii. Scope of variables
In JavaScript, you cannot define a specific block-level scope for a variable, but you can define the function field to which it belongs.
Global variables in JavaScript refer to variables declared outside of all functions
Local variables defined within a function that do not exist outside the function
If the Var statement is not used when declaring a variable inside a function, the variable is default to global (even if it is defined outside of the function). This variable will not exist until the function is called, and the function will be created and given the global scope for the first time after it is called.
Iii. Self-tuning function
A self-tuning function is a function that can be called by itself after a definition, and the basic structure is as follows:
{
function (name) {
alert (' Hello ' + name + '! ');
}
} (' Martin ')
The following () can be passed by parameter, and the value declared in it is automatically passed to the parameter of the function
Using such a custom anonymous function as above does not produce any global variables
Iv. functions that can be rewritten by themselves
The feature of this function is that it can be overridden by itself after execution, and here's an example:
function A () {
alert ("a");
A = function () {
alert ("B")
};
}
When a () is invoked for the first time, alert ("a") is executed and alert ("B") is executed the second time a () is invoked. Because when the function is executed for the first time, it is redefined by the global variable A
The above is a small set of JavaScript to introduce the basic knowledge of the blind spot summary of the function of the relevant knowledge, hope that the above help!