The data type

  1. The base type
  • undefined
  • Null
  • Boolean
  • String
  • Number
  • Symbol
  • BigInt
  1. Reference types
  • Object

Object is divided into Array, RegExp, Date, Math, and Function objects.

Symbol

  1. What is the Symbol type?

The Symbol value is generated by the Symbol function and represents a unique value.

Let tao = Symbol('wyt') console.log(tao) // Symbol(wyt) console.log(typeof tao) // "Symbol"Copy the code
  1. Use of the Symbol type in an object
Let tao = Symbol('wyt') let obj = {} obj[tao] = "wyt"; Console. log(obj[tao]) // "wyt"Copy the code
Let tao = {[tao]: "wyt"} console.log(obj) // {Symbol(wyt): "wyt"}Copy the code
  1. The Symbol type is not enumerable

The Symbol attribute in an object is not changed for… in… Traverse, and will not be the Object. The keys (obj), Object, values (obj), Object, getOwnPropertyNames (obj) return.

let tao = Symbol('wyt')
let obj = {
    other: "hello",
    [tao]: "wyt"
}
for (let key in obj) {
    console.log(key) // "other"
}
console.log(Object.keys(obj)) // ["other"]
console.log(Object.values(obj)) // ["hello"]
console.log(Object.getOwnPropertyNames(obj)) // ["other"]
Copy the code
  1. Through Object. GetOwnPropertySymbols () and Reflect. OwnKeys ()
let tao = Symbol('wyt') let obj = { other: "hello", [tao]: "wyt" } console.log(Object.getOwnPropertySymbols(obj)) // [Symbol(wyt)] console.log(Reflect.ownKeys(obj)) // ["other", Symbol(wyt)] // reflect.ownKeys () returns all attribute keys (including non-enumerable attribute keys)Copy the code

bigInt

  1. What is BigInt

The maximum integer that the Number type can accurately represent is 2^53, while BigInt can represent an arbitrarily large integer

  1. How to declare a value of type BigInt
let val1 = 10n
let val2 = BigInt(10)
console.log(val1 === val2) // true
console.log(typeof val1) // bigint
console.log(Object.prototype.toString.call(val2)) // [object BigInt]
Copy the code

How reference types differ from base types

  1. The base type is stored in == stack memory ==, and when referenced or copied, an exact equivalent variable is created.
  2. Reference types are stored in == heap memory == and store addresses. Multiple references to the same address can lead to data sharing. (Pointers to reference types are stored in stack memory)

== Stack memory == will automatically allocate memory space, automatically release, is a linear structure, last in first out, easy to manage

== Heap memory == Dynamically allocated memory, which is not automatically freed regardless of size.