typeof vs instanceof 如何判断数据类型
看到这一条面试题的时候,感觉还是不够理解。于是自己上网自己查了资料,记录一下。
1⃣️ typeof
typeof只能识别原始数据类型:number、string、boolean、undefine、null、symbol
对于array、object,都只能识别出object
2⃣️instanceof
可以识别复杂类型,通过原型
3⃣️Object.prototype.toString() 最好用
看到这一条面试题的时候,感觉还是不够理解。于是自己上网自己查了资料,记录一下。
1⃣️ typeof
typeof只能识别原始数据类型:number、string、boolean、undefine、null、symbol
对于array、object,都只能识别出object
2⃣️instanceof
可以识别复杂类型,通过原型
3⃣️Object.prototype.toString() 最好用
本文标题:yck前端面试之道总结
本文链接:https://www.haomeiwen.com/subject/zztkpftx.html
网友评论