JS data type

Data type classification

  1. Primitive value types (commonly known as value types, primitive data types)
  • IsNaN & Object.is(Value1,Value2) Infinity: indicates positive Infinity
  • string
  • boolean
  • null
  • undefined
  • symbol

To set up the only objects value attribute (object attribute name types: string, Symbol) Symbol. HasInstance/toStringTag/toPrimitive…

  • bigint

MAX_SAFE_INTEGER/MIN_SAFE_INTEGER Specifies the maximum/minimum safe Number in JS. If n is added to the end of a Number, bigINT is generated. For example: 9007199254740991n, bigINT value to ensure that we exceed the safe number, calculation can also be accurate server returns a large number, we can convert it to bigINT again operation; 2. Object type (commonly known as: reference data type)

  • Standard common object
function Person () {
	this.name = 'Joe'.this.age = 20.this.sayName = function () {
		console.log(this.name); }}Copy the code
  • Standard special object

Arrays, re’s, dates, errors…

  • Non-standard special objects

The value of the primitive type, based on the constructor, is an instance object derived from new

let a = new Number(1);
Copy the code
  • Callable/executable objects (function objects)

function

Data type detection in JS

  1. typeof
  • The result is a string containing the corresponding data type
console.log(typeof typeof typeof 10);	//"string"
Copy the code
  • Limitations (Features)
    • Typeof null results in: “object”
    • Typeof checks object types, returns “object” except function objects.
    • Typeof detects an undeclared variable and returns “undefined”
  • Underlying processing mechanism
    • All data type values are stored in “binary” (64-bit) at the bottom of the computer.
    • The first three digits of the value 000 are considered to be objects (if the object implements the [[Call]]] method, the first three digits are considered to be functions) and the return value is “object”…
    • Because TypeOF is based on low-level judgment, Typeof performs better
  1. instanceof
  2. constructor
  3. Object.prototype.toString.call()

Stack memory for JS execution as well as VO and AO

The browser allocates memory from the computer’s memory bar to store values and run code

  1. Stack: Execution Context Stack
  • Raw value types are stored in stack memory
  • Provide the corresponding execution context EC for code to execute
  • EC(G) global execution context, where global code is executed
    • VO(G) global variable object, which stores variables declared in the global context ** (variables declared based on let/const are stored here, variables declared based on var/function are stored directly in GO) **
  1. Heap: Heap memory
  • Stores the value of the object type
  • GO: Global Object
    • Is allocated a memory space to store the built-in API
  1. Var Variable = value
    • To create value
    • Declare variables
    • Variable and value associated assignment
  2. Use variables in a global context
    • So let’s see if we have VO(G)
    • And let’s see if there’s any in GO
    • If none, an error is reported, the variable is not defined
  3. Variable assignment priority a.x = b = 10;
    • Create value 10
    • A.x is a member access mode with a high priority. Run a.x = 10.
    • b = 10;
    • Normal order: From right to left, operations with higher priorities are performed first

Examples:

var a = {
    n: 1
};
var b = a;
a.x = a = {
    n: 2
};
console.log(a.x);	//"undefined"
console.log(b);		//{ n:1, x:{ n:2 } }
Copy the code