当前位置:网站首页>JS judge the data types object.prototype.tostring.call and typeof
JS judge the data types object.prototype.tostring.call and typeof
2022-07-26 09:38:00 【Bean sprouts don't eat beans】
Take a little note ~
Object.prototype.toString.call and typeof Both are used to judge the data type , The former is more specific to judge the data type , What is returned is string or array , The latter is just a return type .
When we use typeof When judging the data type , It is difficult to distinguish and compare two data types . such as : Use typeof Detection array or null The data types returned during are object, But use Object.prototype.toString.call You can distinguish which is an array , Which number null.
In a nutshell Object.prototype.toString.call You can return data types more specifically .
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(" function ");
}
console.log(Object.prototype.toString.call(a)); // [object Function]
console.log(typeof a); // function
边栏推荐
猜你喜欢
Gauss elimination solves the inverse of matrix (Gauss)
The problem of accessing certsrv after configuring ADCs
Gauss elimination
小白搞一波深拷贝 浅拷贝
图解用户登录验证流程,写得太好了!
微信小程序学习笔记1
2019 ICPC Asia Yinchuan Regional(水题题解)
面试题目大赏
[Online deadlock analysis] by index_ Deadlock event caused by merge
matlab simulink实现模糊pid对中央空调时延温度控制系统控制
随机推荐
TableviewCell高度自适应
Gauss elimination solves the inverse of matrix (Gauss)
(一)面扫描仪与机械臂的手眼标定(眼在手上)
莫队学习笔记(一)
QT handy notes (II) edit control and float, qstring conversion
ie7设置overflow属性失效解决方法
选择器的使用
Basic knowledge of website design
(1) Hand eye calibration of face scanner and manipulator (eye on hand)
Server and client dual authentication (2)
Login module use case writing
微信小程序开发
MySQL的逻辑架构
Jmeter配置元件之CSV数据文件设置
asp. Net using redis cache
Does volatile rely on the MESI protocol to solve the visibility problem? (top)
注册模块用例编写
Solve "note: one or more layouts are missing the layout_width or layout_height attributes."
QT随手笔记(六)——更新界面、截图、文件对话框
Fiddler抓包工具之移动端抓包