Basic data types

There are six common ones

  • Sting
  • Number
  • Boolean
  • null
  • undefined
  • Symbol

Basic data types are held in stack memory because they take up small space, are fixed in size, are accessed by value, and are frequently used data.

Reference data types (complex types)

  • Object
  • Date
  • function
  • RegExp
  • Array …

Reference data types are stored in heap memory because they take up large and variable amounts of memory. If stored in the stack, it will affect the performance of the program; The reference data type stores a pointer on the stack to the starting address of the entity in the heap. When the interpreter looks for a reference value, it first retrieves its address in the stack and then retrieves the entity from the heap

The following two graphs illustrate the differences between the two data storage methods:

Check for primitive and complex types using the constructor syntax: Object instanceof constructor

var a1=0;                 // typedof a1 -> number
var a2 = 'this is str'; //typedof a2 -> string var a3 =null; Typedof a3 -> null var c= [1,2,3]; // c instanceof Array ->true
var b={m:20};         // b instanceof Object ->true
Copy the code

Basic data types and reference data types:

The basic data types are stored on the stack, and the reference data types are stored on the stack, while the reference data types are stored in the heap. If the array (object) M is defined to be equal to the array n (), the address is the same. Therefore, the Pointers to m and N point to the same content.

Stack memory and heap memory

Js memory is divided into stack memory and heap memory.

Stack memory: A special linear table that has lifO and holds basic types.

Heap memory: Store reference types (store a base type value in the stack memory to hold the address of the object in the heap for reference to the object).