Javascript (1)

Source: Internet
Author: User


[Javascript] view plaincopyprint?


I. javascript Variables

Javascript variables can be used to save two types of values: basic type values and reference type values.

 


The basic type value comes from the following five basic data types: Undefined, Null, Boolean, Number, and string. The reference types include object, Array, date, RegExp, function, and basic packaging types (Boolean, Number, and string ).

 


The basic type value occupies a fixed size in the memory, so it is stored in the stack memory. The reference type value is actually an object and is stored in heap memory.

 


Therefore, copying a variable that saves the basic type value creates a copy, while copying a variable that saves the reference type value is actually copying a pointer.

 


You can use the typeof operator to confirm the basic type value, and use the instanceof operator to confirm the reference type.

 


The basic type value is equivalent to a network node, and the reference type is equivalent to a line between nodes. Because of the existence of these nodes and connections, the program becomes a whole and a system.

 


Note: variables can be accessed by value or by reference, but function parameters can only be passed by value.

 


Ii. Reference count

When a variable is declared and a reference type value is assigned to the variable, the number of times this value is referenced is 1. if the same value is assigned with another variable, the value is incremented by 1 ,. For example

[Javascript]
Var element = document. getElementById ("myId ");
 
VAR oBj = element;

Var element = document. getElementById ("myId ");

VAR oBj = element; is a reference process. The reference count is a method for javascript garbage collection. Removing unnecessary references properly helps improve javascript performance.

 

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.