Previous words: JavaScript can be run on all major platforms and on the server side of every mainstream operating system. So, to be a good full-stack engineer, you have to understand JavaScript language. This is my collation of the JS part of the function of the problem, for everyone to refer to the borrowing, there are inappropriate places also please advise.
1. Three elements of a function
Functions of the 1.1 function
1.2 Parameters of the function
A. Formal parameters--when defining a function, there is no actual value, which is a placeholder for the argumentB. Arguments--When the function is called, there are actual values;c. When the function is called, a copy of the argument is passed to the function d. When a function is called, the number of arguments and parameters can varyE. In other languages, there is the concept of overloading, that is, the name of the function is the same, but the parameters are different, but there is no overloaded concept in JavaScript. The function with the same name below overrides the above function
1.3 Return value of the function-returns the result of the calculation
1) function returns, subsequent code does not execute2) If the return is followed by the content, return to the back of the content3) If the return is not followed by the content, the code returned after the Undefined,return does not execute4) If there is no write return value inside the function, return undefined5) The recommended practice is either to have the function always return a value, or never return a value2. Note Points of function parameters
function Funname (A, b) {}
2.1 Determine if the input parameter is empty (filter out undefined null NaN "" 0)
A = a | | 0;B = B | | 0;
2.1 Determine if the input parameter is a number
3. Basic form of function (4 kinds)--No parameter no return value--no return value with parameter--no parameter with return value--parameter has a return value4,/* * + ENTER to comment the function, such as:5. Function call5.1 The
execution of another function is called inside a function:
when the F2 executes, it will return to F1 to continue executing the subsequent code;
1 function F1 () {2 var a = ten; 3 F2 (); 4 }5 F1 (); 6 F1 ();
5.2 calls to itself by functions are called recursive "self-calling functions"
--recursion consumes resources, and errors occur when you call too many times.
5.3 functions are a type of data function
the ① function can be used as a parameter to another function (such as 5.1)the ② function can be used as the return value of a function6. Two methods of function definition
6.1 Function declaration functions fn () {}
6.2 function Expression var myfun = function () {}//the anonymous function is called here
6.3 The difference between a function declaration and a function expression:
i) function declaration--Function Promotion II) function expression--variable promotion (detailed below) 7, scope of the variable
7.1 Global scope: "Global variables" can be accessed at any location
i) variables defined in the SCRIPT Tag II) do not use VAR declared variable III) when you close a Web page or browser, the global variable will not be released
7.2 Local scope: Declare a variable inside the function and use local variables only within the function
i) only variables defined within the function using Var
II) The local variable is destroyed after the function is out of scope
There is no block-level scope in 7.3 javascript
i) block-level scope: In other languages, variables defined in the code block are not accessible externally, and the variables defined using VAR in the IF and for are all global variables
8. Function promotion and variable promotion (process)
8.1 Inside the function, when the variable is obtained, it is searched under the current scope, there is no variable declaration, if any, returns the value of the variable in the current scope.
8.2 If there is no declaration of the corresponding variable in the current scope, return to the previous level to find
1) Parser pre-parsing process:
I, parser
① global scope pre-parsing
varfunction Fun ()
② A line of code execution
a) num = ten; b) Fun (); Call the fun function i) fun's local scope one. Pre-parse first . var num; Both. Executes code first on one line. Console.log (num); Output undefined Second. = 20;
var num; function Fun () { var num; Console.log (num); =; } = ten; Fun ();
var num = ten; fun (); function Fun () { var num; Console.log (num); =; // inside the function to access external variables var a = ten; function fn () { console.log (a); }
2) Variable promotion--when defining a variable, the declaration of the variable is promoted to the top of the scope, and the assignment of the variable does not increase by 3) The function promotion The--JAVASCRIPT parser will first advance the function declaration of the current scope to the front of the entire scope
9. Constructors and custom Constructors
9.1 Constructors: Constructs an object, and the returned function--Call constructor: var student = new Object (); The purpose of the ① constructor is to create objects ② use the new object () to create objects ③ encapsulate functions to create multiple objects ④ custom constructors
9.2 Custom Constructors
① memory opens up space to store newly created objects new object ();
② will set this to the current object
③ executing the code inside the function, setting the properties and methods of the object
④ returning the newly created object
On the function problem in JavaScript