JavaScript Chapter Fourth

Source: Internet
Author: User
Tags extend

Tag: Boolean access obj error border code execution cell problem code

variables, scopes, and memory issues

    1. Values for base types and reference types

(1) Basic type: Access by value (Undefined, Null, Boolean, number, String)

(2) Reference type: Access by reference

Basic type

Reference type

Dynamic Properties

Cannot add property to a base type value

Dynamically adding, changing, deleting properties and methods

Copy variable values

Creates a new value on the variable object, and then copies the value to the location of the new variable assignment (non-impact)

Copy end two variables referencing an object (interrelated)

Passing parameters

Copy the values outside the function to the parameters inside the function

Copy the memory address of this value to another local variable

Detection type

Use typeof to detect the base type, and if it is null or an object, return "object" = = = Returns a String type

Use instanceof to detect specific types: objects, arrays, or regular. Syntax: result = Variable instanceof constructor.

    1. Execution Environment and scope

The execution environment defines which variables or functions have access to other data, determines their respective behavior, and has a variable object associated with it, and all variables and functions defined in the environment are stored in the object.

All global variables and functions are created as properties and methods of the Window object. After all code in an execution environment is executed, the environment is destroyed, and all the variables and function definitions stored therein are destroyed.

When code executes in an environment, the scope chain of the variable object is created, guaranteeing an orderly access to all variables and functions that the execution environment has access to.

The internal environment can access all external environments through the scope chain, but the external environment cannot access any variables and functions in the internal environment. The relationships between environments are linear in order and can only be searched up the scope chain to query for variables and function names; the subordinate scope chain contains the object: its own variable object and the ancestor of the variable object, until the global variable object.

Identifier parsing is the process of searching identifiers one level at a scope chain. The search process starts at the front end of the more-scoped chain, and then goes backward backwards, knowing that the identifier location is found and, if not found, causes an error.

Extend the scope chain

Type of execution Environment: global and local;
Extend the scope chain: Some statements can temporarily add a variable object to the front of the scope chain, and the variable object is removed after the code executes. The following two statements add a long scope chain:

    • The catch block of the Try-catch statement (creates a new variable object that contains the thrown error object declaration)
    • With statement (adds the specified object to the scope chain)

No block-level scopes

Variables are added to the current execution environment,
Variables declared with Var are automatically added to the nearest environment, within the function, most recently in the local context of the function, the closest function environment to the WITH statement, without the use of Var initialization, is automatically added to the global environment (it is not recommended to use, strict mode, Initializing an undeclared variable causes an error).

Query identifiers

Identifier (variable name): query, first in the local environment to find, not found to continue to search upward, until the global environment of the variable object, if not found, it is not declared. If found, stops the search and does not enter the next variable object. (Local environment has, then the parent's identifier is not used)

    1. Garbage collection

JavaScript has an automatic garbage collection mechanism.

tag Cleanup (the most common garbage collection method)

Variables can be tagged in any way

Reference count

Trace records the number of times each value is referenced. The code does not apply when there is a circular reference phenomenon.

JavaScript Chapter Fourth

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.