当前位置:网站首页>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
边栏推荐
猜你喜欢
js在控制台输出菱形
服务器、客户端双认证(2)
MySQL transaction
tabbarController的使用
Your login IP is not within the login mask configured by the administrator
2022 tea artist (intermediate) special operation certificate examination question bank simulated examination platform operation
Basic use of ArcGIS 4
csdn空格用什么表示
asp.net 使用redis缓存
cocoapods的安装和使用
随机推荐
添加dll
el-table的formatter属性的用法
Solve "note: one or more layouts are missing the layout_width or layout_height attributes."
QT随手笔记(六)——更新界面、截图、文件对话框
Basic use of Arc GIS 2
大二上第五周学习笔记
TabbarController的封装
[Online deadlock analysis] by index_ Deadlock event caused by merge
什么是异步操作
v-for动态设置img的src
注册模块用例编写
正则表达式
nodejs中mysql的使用
When you click input, the border is not displayed!
暑假第四周
Drawing shadow error diagram with MATLAB
V-for dynamically sets the SRC of img
a-table中的rowSelection清空问题
JS output diamond on the console
VectorTileLayer更换style