当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
如何添加一个PDB
ie7设置overflow属性失效解决方法
Use of OpenCV class
I'm faded
Neural network and deep learning-6-support vector machine 1-pytorch
asp. Net using redis cache (2)
官方颁发的SSL证书与自签名证书结合实现网站双向认证
sublime 安装插件
一种分布式深度学习编程新范式:Global Tensor
图解用户登录验证流程,写得太好了!
tabbarController的使用
JS one line code to obtain the maximum and minimum values of the array
nodejs中mysql的使用
asp.net 使用redis缓存
服务器、客户端双认证
Android implements the caching mechanism and caches multiple data types
IIS网站配置
keepalived 实现mysql自动故障切换
WARNING: [pool www] server reached pm.max_children setting (5), consider raising it
Qt随手笔记(二)Edit控件及float,QString转化、