Types and determination js

6 basic types: boolean, string, number, undefined, null, symbol

Analyzing basic types: typeof

1 typeof 'a'; //"string"
2 typeof 1; //"number"
3 typeof true; //"boolean"
4 typeof undefined //"undefined"
5 typeof Symbol('1') //"symbol"
6 typeof null; //"object"

Analyzing Object Type: instanceof (typeof is because the object 'object')

1 function person(name) {
2     this.name = name
3 }
4 var mm = new person('妹妹');
5 mm instanceof person; // true

instanceof principle: 

mm .__ proto __. constructor === person or mm .__ proto __ .. (__proto __........ the prototype chain) .__ proto __. constructor === person

 

Analyzing several ways array:

[] instanceof Array;

Array.isArray([]);

Array.prototype.isPrototypeOf([]);

Object.prototype.toString.call([]) === '[object Array]';

 

Guess you like

Origin www.cnblogs.com/vicky24k/p/11785458.html