Java learning process may involve JavaScript, although it is not the focus of learning, but we also need to master, for our programming road will be helpful, the following will introduce some basic knowledge of JS.
Execution environment: Sometimes called an environment, it is the most important concept in JavaScript. The execution environment defines other data that a variable or function has access to.
2. Variable object: Each execution environment has a variable object associated with it. All variables and functions defined in the environment are stored in this object.
3. Scope chain: When code executes in the environment, it creates a scope chain of variable objects to ensure orderly access to all variables and functions that the execution environment has access to. At the front of the scope chain is always the variable object of the environment in which the code is currently executing.
4. Active object: If the current execution environment is a function, use the active object as a variable object.
1) Global code: such as loading external JS files or codes inside local tags, global code does not include the code inside function; 2) Function code: code inside function; 3) Eval code: The eval() function evaluates a string and executes the JS code within it, such as eval(“alert(‘hello world’)”).
6, execution context stack: in a JS program, there will be multiple execution context, JS engine will stack to deal with them, that is, the execution context stack.
7, scope: JS is a language that no block-level scope (including the if and the for statement of curly braces code block or separate brace code block can form a local scope), so JS and only the function of the formation of the local scope of curly braces defined in the code block formation, both function scope.
8, scope chain: is the implementation of scope rules, through the implementation of scope chain, variables in its scope can be accessed, functions in its scope can be called. A scoped chain is a one-way list, in which each node is the variable object of the execution context. The head of the one-way list (the first node accessible) is always the variable object of the function currently being invoked (the active object), and the tail is always the global active object.
Closure: Function objects can be related to each other through scope chains, and the data inside a function (variables and function declarations) can be stored in the function scope, a feature known in the computer science literature as “closures.” Technically, JS functions are closures: functions are objects, are associated with scope chains, and data is stored in the function scope.