typeof 区分类型的原理
时间: 2023-05-31 14:04:09 浏览: 103
JavaScript 的 typeof 运算符可以用来获取一个值的类型。它根据值的类型返回以下字符串之一:
- `"undefined"`:未定义的值。
- `"boolean"`:布尔值。
- `"number"`:数值。
- `"string"`:字符串。
- `"symbol"`:符号(ECMAScript 6 新增)。
- `"object"`:对象、数组、null(注意:null 是一个特殊的对象)。
- `"function"`:函数。
typeof 运算符的原理是根据值的类型来确定其返回值。对于基本类型的值(undefined、boolean、number、string 和 symbol),typeof 运算符的返回值是明确的。对于对象和函数类型的值,typeof 运算符的返回值是 "object" 和 "function",但是它们之间的区别可以通过其他方式来确定。例如,可以使用 instanceof 运算符来检查一个值是否是特定类型的对象。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)