1. Standard definitions of data types in ECMAScript262
Overview ECMAScript is object-based: basic language and host facilities are provided by objects, and an ECMAScript program is a cluster of communicating objects. In ECMAScript, an object is a collection of zero or more properties each with attributes that determine how each property can be Used — for example, when the Writable attribute for a property is set to false, any attempt by executed ECMAScript code to assign a different value to the property fails. Properties are containers that hold other objects, primitive values, or functions. A primitive value is a member of one of the following built-in types: Undefined, Null, Boolean, Number, String, and Symbol; an object is a member of the built-in type Object; and a function is a callable object. A function that is associated with an object via a property is called a method. ECMAScript is object-based: the basic language and host facilities are provided by objects, while ECMAScript programs are clusters of communicating objects. In ECMAScript, an object is a collection of zero or more properties, each of which has properties that determine how each property is used — for example, any attempt to execute ECMAScript code to assign a different value to a property when its writable property is set to false will fail. Properties are containers that hold other objects, base values, or functions. Primitive values are members of one of the following built-in types: undefined, Null, Boolean, number, string, and symbol; Object is a member of an object of built-in type; Functions are callable objects. Functions that are associated with objects through attributes are called methods.
ECMAScript defines a collection of built-in objects that round out the definition of ECMAScript entities. These built-in objects include the global object; objects that are fundamental to the runtime semantics of the language including Object, Function, Boolean, Symbol, and various Error objects; objects that represent and manipulate numeric values including Math, Number, and Date; the text processing objects String and RegExp; objects that are indexed collections of values including Array and nine different kinds of Typed Arrays whose elements all have a specific numeric data representation; keyed collections including Map and Set objects; objects supporting structured data including the JSON object, ArrayBuffer, and DataView; objects supporting control abstractions including generator functions and Promise objects; And, Reflection Objects including Proxy and Reflects. ECMAScript defines a collection of built-in objects that complete the definition of ECMAScript entities. These built-in objects include global objects; Objects are the basis of language runtime semantics, including objects, functions, booleans, symbols, and various error objects. Objects that represent and manipulate numeric values, including mathematics, numbers, and dates; Text processing object strings and regexps; Object, which is an indexed collection of values, including arrays and nine different types of arrays, whose elements have a specific numeric data representation; Keyed collections, including Map and Set objects; Objects that support structured data, including JSON objects, ArrayBuffers, and DataViews; Support for control abstraction objects, including generator functions and promise objects; And reflection objects, including proxies and reflections
- Primitive value type [value type/primitive data type]
- The number of digital
- String string
- Boolean Boolean
- Null Null object pointer
- Undefined undefined
- The only value symbol
- Bigint tarsus
- Object type [reference data type]
- Standard common object Object
- Standard special object Array RegExp Date Math Error…
- Nonstandard special object Number String Boolean
- Callable/executable object function
2. Underlying mechanism of Typeof data type detection
-
Feature 1: The result is a string containing the corresponding data type
-
typeof typeof typeof [1.2.3] //'string' Copy the code
-
-
Feature 2: Detection is carried out according to the binary stored at the bottom of the computer [High efficiency]
- Objects that start with 000
- An integer starting with 1
- A floating point number starting with 010
- A string starting with 100
- Start with 110 Boolean
- 0000… null
- -2^30 undefined
- .
-
Typeof NULL -> ‘object’ //null is stored in binary with all 000… So it’s going to be object
-
Typeof ‘object’ -> ‘object’ typeof ‘function /class’ -> ‘function’
- Verifies whether it is an object or not
-
Typeof ‘undeclared variables’ -> ‘undefined’
- Exposed apis in plug-in packaging
-
/ * data type testing * 1 * * * 2. The typeof instanceof * 3. The constructor * 4. The Object. The prototype. ToString. Call ([value]) - * * * * Array.isArray * isNaN * ... * * Typeof underlying processing mechanism */ // Expose API in plug-in package // (function () { // let utils = { / /}; // if (typeof window ! == "undefined") window.utils = utils; // if (typeof module === "object" && typeof module.exports === "object") module.exports = utils; / /}) (); // utils.xxx(); Copy the code
3. JS underlying storage mechanism: Heap and Stack memory
- The following code is used as an example
var a = 12; //window.a = 13
var b = a;
b = 13;
console.log(a) 12
let b = 14
const c = 15
d = 16 //window.d = 16
Copy the code
- The following code is used as an example
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