当前位置:网站首页>JS判断数据类型 Object.prototype.toString.call和typeof
JS判断数据类型 Object.prototype.toString.call和typeof
2022-07-26 09:30:00 【豆芽不吃豆】
做个小笔记~
Object.prototype.toString.call和typeof 二者都是用来判断数据类型的,前者更具体的去判断数据类型,返回的是字符串或者数组,后者只是返回类型。
当我们使用typeof去判断数据类型的时候,很难区分比较两个数据类型。比如:使用typeof检测数组或者null时返回的数据类型都是object,但是使用Object.prototype.toString.call就能区分得到哪个是数组,哪个数null.
简单来说就是Object.prototype.toString.call可以更具体的去返回数据类型。
console.log(Object.prototype.toString.call("aaa")); // [object String]
console.log(typeof "aaa"); //string
console.log(Object.prototype.toString.call([123])); // [object Array]
console.log(typeof [123]); // object
console.log(toString.call(null)); //[object Null]
console.log(typeof null); // object
function a() {
console.log("函数");
}
console.log(Object.prototype.toString.call(a)); // [object Function]
console.log(typeof a); // function
边栏推荐
- Does volatile rely on the MESI protocol to solve the visibility problem? (top)
- What is asynchronous operation
- Implementation of fragment lazy loading after multi-layer nesting
- Audio and video knowledge
- After attaching to the process, the breakpoint displays "currently will not hit the breakpoint, and no symbols have been loaded for this document"
- 大二上第三周学习笔记
- Basic use of ArcGIS 4
- “互联网+”时代的现代医学
- a-table中的rowSelection清空问题
- 如何添加一个PDB
猜你喜欢
随机推荐
After attaching to the process, the breakpoint displays "currently will not hit the breakpoint, and no symbols have been loaded for this document"
高斯消元求解异或线性方程组
什么是异步操作
Malloc failed to allocate space and did not return null
EOJ 2020 1月月赛 E数的变换
arc-gis的基本使用2
Custom password input box, no rounded corners
mysql5.7.25主从复制(单向)
The provincial government held a teleconference on safety precautions against high temperature weather across the province
暑假第四周
2022 chemical automation control instrument operation certificate test question simulation test platform operation
C# 托管与非托管
[Online deadlock analysis] by index_ Deadlock event caused by merge
正则表达式
POJ 1012 Joseph
Audio and video knowledge
配置ADCS后访问certsrv的问题
asp.net 使用redis缓存(二)
服务器、客户端双认证(2)
神经网络与深度学习-6- 支持向量机1 -PyTorch







