
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,我们会在看到邮件的第一时间内为您处理!

vue项目中v-slot具名插槽的使用方法
动手学深度学习:实践驱动的深度学习入门与进阶指南
DeepSeekMine:本地运行的AI智能知识管理软件,附客户端下载软件
Intern-S1-Pro:上海AI实验室开源的万亿参数科学多模态大模型
ComfyUI-LaoLi-Shadow安装插件入口,面向ComfyUI的底层性能加速插件
ReadyBase官网:文档可导出为PDF、高分辨率图片等多种格式