js基本数据类型:boolean、null 、 underfined 、 string、number
引用类型:date、array、object、function
1、typeof判断。
适合判断基本数据类型: eg:let x = "123"; console.log(typeof x) ; string
判断引用类型的时候: eg : let x = [1,2]; console.log(typeof x); object
let y = new Function(); console.log(typeof y); function
2、instanceof判断
适合判断引用类型: eg :let x = [1,2]; console.log(x instanceof Array) ; true
3、constructor判断
eg:let x =[1,2] ;console.log(x.constructor === Array); true;
问题:function A (){};function B(){}; B.prototype = new A(); let x = new B(); console.log(x.constrcotor==A) ;true
console.log(x.constrctor==B);false
4、Object.proptotype.toString.call()判断
eg:let x = "123";console.log(Object.prototpye.toString.call(x)=="[object string]");true;
5、jQuery.type()判断
eg:let x = new date();console.log(jQuery.type(x));Date();