function an object in which functions can be encapsulated, and when a function object is checked with typeof, it returns function
Create a Function object
var function = new function ();
The code that you want to encapsulate can be passed to the constructor in the form of a string
var function = new Function ("Console.log (' xxxxxxxx ');");;
Syntax for calling functions: Function object (), Functions ()
Use a function declaration to create a function
Grammar:
Function name (formal parameter list) {
function body;
}
Use a function expression to create a function:
Grammar:
var fun = function (formal parameter list) {
function body;
}
When invoking a function, the parser does not check the type of the argument, nor does it check the number of arguments, the extra arguments are not assigned, the number of arguments is less than the number of formal parameters, and the shape arguments without the assignment is undefined
Return is not written, it is equivalent to returning undefined, and if you do not write a return statement, you will return a undefined
Return value can be any type, can be an object, or it can be a function
function Fun3 () { // inside the function, declare a functions fun4 () { alert (" I am fun4"); } // returns the Fun4 function object as a return value return = fun3 (); // a (); Fun3 () ();
Execute the function immediately:
function () { alert ("xxxxxx");} // the above is the wrong wording
(function () { alert ("xxxxxx");}) (); // Execute now
JS Basics (Functions)