

Obj2 is not equal to the value of OBj1, but is equal to the address that OBj1 stores in the heap, so when the address changes, so does the content of obj2. We refer to these as primitive data types. The five most basic types of data are strings, numbers, booleans, undefined, and null.

When A changes, B does not change, because B is just equal to the value of A and has nothing to do with A.īoth obj1 and OBj2 store addresses. In Javascript, there are five basic, or primitive, types of data. The object is then stored on the stack as its address in the heap.Īs shown in the figure above, the basic data types store values directly on the stack. If it is an object, it is divided into an area of a larger heap. When a new variable is created, it is stored on the stack. So why? In a nutshell: because basic data types store values, reference types store addresses. The basic data type that is assigned does not change, while the reference that is assigned will change accordingly. There are six data types in JS, including five basic data types (Number, String, Boolean, null, undefined), and a mixed data type is special (Object 'undefined' Variable is not defined &qu. A string may have zero or more characters, there’s no separate single-character type. bigint for integer numbers of arbitrary length. Seven primitive data types: number for numbers of any kind: integer or floating-point, integers are limited by (2 53-1).

You can see that both of the above examples change values. There are 8 basic data types in JavaScript. JS type only 6 species, in which there are five basic data types, respectively, to a string, number, boolen, null, and undefined, there is a reference type, is the object, the object is a large, complex, in addition to the five basic data types in the JS, everything in the other object. This article brings you the content is about javascript basic data type and reference type difference analysis, there is a certain reference value, friends in need can refer to, I hope to help you.
