Basic JS types and reference types, and basic js references

Source: Internet
Author: User

Basic JS types and reference types, and basic js references

Js:

1. The ECMAScript variable contains two different types of values: basic type value and reference type value;

2. Basic Type value: refers to the simple data segment stored in the stack memory;

3. Reference Type value: refers to the objects stored in the heap memory. It means that the objects stored in the variable are actually just a pointer, and this pointer is executed in another location in the memory, stores objects at this location;

Two access methods:

4. Basic Type value: access by value and operate on the actually saved values;

5. Reference Type value: access by reference. When querying, We need to read the memory address from the stack first, and then find the value stored in the heap memory;



Two types of Replication

 

1. Replication of basic type variables: When copying a variable to a variable, a new value is created in the stack, and then the value is copied to the location assigned to the new variable;




 

1. Copy of reference type variables: Copies the pointer stored in the stack and copies the pointer to the space not allocated by new variables in the stack, the pointer copy and the original pointer execute the same object stored in the heap;

2. After the copy operation is complete, the two variables will actually reference the same object. Therefore, changing one of them will affect the other;



Function parameter transfer:

 

1. All function parameters in ECMA are passed by value;



Two types of Variables

 

1. The Typeof operator is the best tool for detecting basic types;

2. If the variable value is nul or object, typeof will return "object ";

3. Instanceof is used to detect the reference type. It can detect the specific instance type;

4. If the variable is an instance of the given reference type, the instanceof operator returns true;



 

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.