相同点:instance of和 type of 都是类型的判断
不同点:
type of:type of test 会直接返回test的类型数据,返回数据类型必为以下的6个之一:undefined, number, string, boolean.object,function
instance of: test1 instance of test2 是用来判断test1是不是属于test2的实例的,返回值王诶true or false
判断是不是数组:type of在判断 数组、对象、null时得到的结果都是object,不能判断该值是否为数组;
instance of可以判断是否为数组
文章探讨了JavaScript中`instanceof`和`typeof`两个操作符的相似点和不同点。`typeof`返回变量的六种基础类型,而`instanceof`用于检查一个对象是否是另一个对象的实例。特别地,`typeof`无法准确判断数组,总是返回`object`,而`instanceof`能用于识别数组。
253

被折叠的 条评论
为什么被折叠?



