1, let var const
Function promotion takes precedence over variable promotion, which puts the whole function at the top, whereas variable promotion just puts the declarator at the top.
Var is improved to use undefined before it is declared.
Let, const cannot be because it creates a temporary dead zone
Let does not allow the same variable to be declared twice in the same scope.
Const declares a basic type as a constant and cannot be modified. Declared objects can be modified.
2, typeof
Typeof Displays normally for basic types except null
typeof 1 // 'number'
typeof '1' // 'string'
typeof undefined // 'undefined'
typeof true // 'boolean'
typeof Symbol() // 'symbol'
typeof null // 'object'
typeof [] // 'object'
typeof {} // 'object'
Copy the code
3, Instance of principle
Instanceof can correctly determine the type of object by looking it up in a chain of prototypes
function myInstanceof(left,right){
let prototype = right.prototype;
left = left.__proto__;
while(true){
if(left === null || left === undefined)
return false
if(prototype === left)
return true
left = left.__proto__
}
}
Copy the code
4. Prototype and prototype chain
Each function has its own prototype
Every object has a __proto__ attribute,
Points to the prototype of the constructor that created the object. In fact, this attribute refers to prototype, so using proto to access objects can find attributes that don’t belong to that object by __proto__. Proto connects objects together to form a prototype chain