Assignment of js basic data types and reference data types

js data type

There are 8 types of js data

In ES5, there are 6 types of data:Number、String、Boolean、undefined、object、Null。

One is added in ES6 Symbol. Objects of this type are never equal, even if the same value is passed in when they are created. Can solve the problem of attribute name conflict, as a mark.

A kind of bigInt appeared in Google 67 version. Refers to safe storage and manipulation of large integers. (But many people do not regard this as a type).

js data type:
Number、String、Boolean、Null、undefined、object、symbol、bigInt

It includes: basic data types, complex data types, and reference data types.
Basic data types: All
reference data types except Object : object, which contains function, Array, and Date

For the basic data type, its value is stored directly in the stack memory, while for the reference type, it only stores a reference in the stack memory, and the real data is stored in the heap memory

When we operate on data, two things happen

1. Basic data type
Insert picture description here
We can see that the value of basic data type data is assigned to a variable stringA, and then the value of a is assigned to the variable stringB. After the modified stringBvalue, the value that can be seen stringBhas been modified, but stringAthe value has not been modified . Both variables use independent data.

Second, the reference data types
Insert picture description here
can be seen that the value of the two objects have been modified
object is a reference type of value for reference types, we will be objgiven newObjthe time, in fact, just put objin the stack heap storage The reference is given newObj, and the two objects at this time point to the same data in the heap memory, so when we modify any value, the data in the heap memory is modified, not the reference, so just modify , The value of the same referenced object also changes naturally.

If you need to change the value of the referenced array without changing the original array, please see the next article:

Guess you like

Origin blog.csdn.net/weixin_52400118/article/details/112802826