JavaScript has seven basic types: String, Number, Boolean, Null, Undefined, Symbol, Object, the first six are primitive data types, and Object is a reference type. Functions are essentially of the Object type, i.e., an object.
It is worth noting that
typeof (null)will returnObject, this is because if the first three bits of the binary inJSare all0, it will be considered as anObjecttype. The binary representation ofnullis all0, so naturally the first three bits are also0, hence when executingtypeof, it will returnObject, whereas in reality,nullis a primitive data type.
Construct a Student class, and instantiate a Student to create the stu instance object.
Every function object has a prototype property. The prototype is the prototype of the instance object created by calling the constructor function, and the prototype allows all object instances to share the properties and methods it contains.
__proto__ is actually used in prototype chain lookup. It always points to prototype, i.e., it points to the prototype object of the constructor function Student. For example, the instantiated stu will use __proto__ to look for methods or properties in Student’s prototype. If stu finds the called method or property, it will not use __proto__ to search the prototype object.
Each prototype has a constructor property that points to the associated constructor function Student, and the instance's constructor points to the constructor function Student.
The prototype chain can be simply understood as connecting the prototypes into a chain, and every time js retrieves an object's property, it performs a search process. If it cannot be found in its own properties, it will then search in the prototype object. If it still cannot be found in the prototype object, it will go to the prototype's prototype for a search, that is, it searches following the prototype chain until it reaches the top of the prototype chain, i.e., the prototype of Object.