One, variable scope
Variable scope refers to the scope of the variable, the variables in JavaScript are divided into global variables and local variables
1. Global variables: variables defined outside the function are common to the entire page and can be accessed inside and outside the function.
2. Local variables: variables defined inside a function can only be accessed within the function that defines the variable, and cannot be accessed externally. When accessing a variable inside a function, first look inside for the variable, if there is, use internal, if not, go outside to find
second, closed functionA closed function is another way of writing an anonymous function in JavaScript, creating a function that executes at the outset without naming it. 1. Definition and execution function of general function2. Definition and execution of closed functions: (function () {...}) You can also add "~" or "!" before the function definition Symbol to define an anonymous function.
three, closed package
Closures are function nesting functions, and intrinsic functions can reference parameters and variables of external functions, and parameters and variables are not reclaimed by the garbage collection mechanism.
1, closure purposes 1: A variable is stationed in memory for a long time, can be used in the loop to save the index value
2, Closure purposes 2: Private variable counter, external inaccessible, to avoid pollution of global variables
Iv. built-in objects1. Document
For example, when viewing the Product Details page, want to buy, this will jump to the login page, after the successful login to use this method to jump to the Product details page
document.referrer//get the address of the previous Jump page (requires server environment)
2. location
A, window.location.href//Get or reset URL address
B, Window.location.search//Get Address Parameters section
C, Window.location.hash//Get page anchor point or hash value
3. Math
A, math.random get a random value of 0-1
B, Math.floor down rounding
C, Math.ceil Upward rounding
JS closed functions, closures, built-in objects