javascript-Scope-Memory

Source: Internet
Author: User

First, basic type and value of reference type

Dynamic Properties

To create an object:

1. constructor Creation : New Object

2. literal creation :{}

Object Add Property: object . Property name = value

Object Add Method: object . Method Name =function () {}

Copy variable values

1. Reference type: If it is an assignment state, the reference type is common and one object is affected by each other

2. Basic type: If it is an assignment state, it is equivalent to copying a copy

(Clone version) 2 variables are separate and do not affect one another

C. passing Parameters

function ( parameters ): Parameters === "can only pass values

D. detection Type

instanceof=== Returns a Boolean value (object instanceof detection value (e.g. String,object))

if the match returns true

False if no match is returned

JavaScript storage **********

1. stack memory (base type)

2. heap memory (reference type)

Second, the scope in JS

Code ( variable | function ) The role in a certain place

1. at the global level, declared variables and functions are actually Properties or methods of the Window object.

2. For example, declaring a local variable in a function cannot be hit globally

the scope chain in JS

Internal access to external local variables or functions

External cannot access internal local variables or functions

Priority level

1. First find this layer ( this scope ) ===> Step-by-step outward lookup

2. Priority Level

variable ---> function ---> parameters ----> elevation

function (declaration)= = ="Does not look at the order of execution

Things that declare variables

var a ===> local a

WINDOW.A ====> Global a

a ====> belongs to the local a, also belongs to the global a

function fn () {

A = 10; ==> belong to the interior, also belong to the outside

Console.log (a);

var A; // after lifting the top a =10 not belong to the inside and outside , belong to the interior only

}

FN ();

Third, JS garbage collection mechanism

1. Mark Clear

One of the most commonly used garbage collection mechanisms

2. Reference Counting

The least common kind of garbage collection mechanism

3. Manual Removal

use a variable or object or function = = =Null (assigned to)

javascript-Scope-Memory

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.