typeof 的取值类型范围 以及 typeof和 instanceof 的区别

                               **typeof的取值范围**

typeof运算符用来检测给定变量的数据类型,返回一个用来表示表达式的数据类型的字符串。 可能的返回值有:“number”、“string”、“boolean”、“object”、“function” 和 “undefined”
在这里插入图片描述
** typeof和 instanceof 的区别**
相同点

JavaScript 中 typeof 和 instanceof 常用来判断一个变量是否为空, 或者是什么类型的。
不同点:

typeof:
1.返回值是一个字符串, 用来说明变量的数据类型。
2.typeof 一般只能返回如下几个结果: number, boolean, string, function, object, undefined。
在这里插入图片描述
instanceof:
1.返回值为布尔值;
2. instanceof 用于判断一个变量是否属于某个对象的实例。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_43287934/article/details/83311150
今日推荐