1.1 typeof ()

Disadvantages: Cannot identify object,array, or NULL

console.log(typeof({}))		//object
console.log(typeof([]))		//object
console.log(typeof(null))	//object
Copy the code

1.2 instanceof

Using prototype

console.log([] instanceof Array)	//true
console.log({} instanceof Object)	//true
Copy the code

1.3 the constructor

Using the constructor,

Disadvantages: can’t judge null and undefined, and can lead to pointing errors if prototype is overwritten

let str='123'	
let num=1		
let obj={}		
let arr=[]		
let isNull=null		
let isUndefined=undefined	
console.log(str.constructor)	//[Function: String]
console.log(num.constructor)	//[Function: Number]
console.log(obj.constructor)	//[Function: Object]
console.log(arr.constructor)	//[Function: Array]
console.log(isNull.constructor)		//error
console.log(isUndefined.constructor)	//error
Copy the code

1.4 the toString ()

Using the method of the Object prototype Object. The prototype. The toString ()

let str='123'
let num=1
let obj={}
let arr=[]
let flag=true
let isNull=null
let isUndefined=undefined
console.log(Object.prototype.toString.call(str))	//[object String]
console.log(Object.prototype.toString.call(num))	//[object Number]
console.log(Object.prototype.toString.call(obj))	//[object Object]
console.log(Object.prototype.toString.call(arr))	//[object Array]
console.log(Object.prototype.toString.call(flag))	//[object Boolean]
console.log(Object.prototype.toString.call(isNull))	//[object Null]
console.log(Object.prototype.toString.call(isUndefined))	//[object Undefined]
Copy the code

Feel free to like and comment if you find it helpful. The views expressed above are personal. Please correct any errors. If you are interested in the front, welcome to my personal blog sundestiny. Making. IO/myblog /