On the basic types and reference types of JS _javascript skills

Source: Internet
Author: User

Two types of:

The ECMAScript variable contains two different types of values: the base type value, the reference type value;

Base type value: Refers to a simple data segment stored in the stack memory;

Reference type value: Refers to those objects stored in the heap memory, meaning that the variable is actually stored in a pointer, which points to another location in memory where the object is saved;

Two ways of accessing:

Basic type values: accessed by value, the value they actually save is the operation;

Reference type value: accessed by reference, when the query, we need to read from the stack of memory address, and then follow the trace to find the value stored in the heap memory;

Two types of replication

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

2. Replication of reference type variables: Copy the pointer stored in the stack, and copy the pointer to the space allocated for the new variable in the stack, and the pointer copy and the original pointer point to the same object stored in the heap;

After the copy operation is finished, two variables will actually refer to the same object, so changing one of them will affect the other.

The above article on the basis of JS type and reference type is small series to share all the content of everyone, I hope to give you a reference, but also hope that we support the cloud habitat community.

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.