
typeof是用来求值结果作为其操作数的类型结果字符串,属于一元运算符。还可以替代语法是在括号中使用操作数,这对于检查JavaScript表达式返回值的类型非常有用。下面web建站小编给大家详细介绍一下具体使用方法!
基本用法:
typeof "web"; // 'string'
typeof 22; // 'number'
typeof NaN; // 'number'
typeof Infinity; // 'number'
typeof true; // 'boolean'
typeof false; // 'boolean'
typeof [1, 2]; // 'object'
typeof {age: 22}; // 'object'
typeof null; // 'object'
typeof undefined; // 'undefined'
typeof String; // 'function'
typeof Boolean; // 'function'
typeof Number; // 'function'
typeof Object; // 'function'
typeof Function; // 'function'
typeof person; // 'function'
检测值是否存在在不同环境:
if (typeof window !== 'undefined') {
// 浏览器
};
if (typeof process !== 'undefined') {
// Node.js
}
if (typeof $ !== 'undefined') {
// jQuery
}
jquery如何判断某个元素是否存在(判断元素是否存在某个属性)
js如何获取当前对象的类型(number/string/boolean)
上面是“js中typeof语法有什么作用”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_3637.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

一款专为小红书博主设计的自动化运营工具——自动薯
关键词在网站中是如何布局的?
php语法如何清空数组中所有元素