web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

js中typeof语法有什么作用

356 ℃
     

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)

javascript一元运算符介绍方法

标签: typeof, 一元运算符

上面是“js中typeof语法有什么作用”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_3637.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > js
本文共计622个字,预计阅读时长5分钟
生活小工具,收录了80多款小工具
上一篇: 推荐一款免费在线图片处理工具——佐糖图片平台
下一篇: 推荐一款优设网免费可商用字体——优设标题黑体
x 打工人ai神器