There are two common function declarations: declarative functions, expression functions
1. Declarative functions: Function Add (A, b) {
return a+b;
}console.log (add);//Return 3
2, the expression of the function (after the end of the statement will be added ";")
var saysomething=function (a) {
Console.log (a)
};saysomthing ("Hello World")
Second, immediately execute the function:! function () {Console.log ("the");} ();
The parameter passed in when the function is called is called an argument, and the parameter when declaring the function is a formal parameter.
Four, the variable increase: 1, find Var defined variables.
2, find the function of the declaration type:
var add=function (A, b) {
return a+b;}
Console.log (ADD)
When pre-parsing, the browser parses the variables defined by VAR, assigns the undefined to the variable, and then parses the declarative letter
Number
V. Scope of functions: global scope, local scope (scope of function)
var a=2;
function test () {var a=1;} Console.log (a)//return 2
function test () {var a=1;console.log (a)}//returns 1
Global variables work globally, local scopes are function scopes, and the values of variables only function locally.
The basic data types are stored in the stack, object types are stored in the heap, object types are address-passing, basic types
is a value pass.
JS Function Basics