1. typeof 运算符

  typeof 可以判断基本数据类型:

  typeof 123; // "number"

  typeof 'abc'; // "string"

  typeof true; // "boolean"

  碰到复合数据类型的情况:

  typeof {}; // "object"

  typeof []; // "object"

  var f = function(){};

  typeof f; //'function'

  

  特殊情况:

  1.typeof null; // "object" 这是历史遗留问题,不做深究,是个隐藏的坑

  2. typeof undefined; (undefined指未定义的变量)// “undefined”

  利用这个特点 用于判断语句

if (v) {
// ...
}
// ReferenceError: v is not defined // 正确的写法
if (typeof v === "undefined") {
// ...
}

综上,利用typeof 得到值就有"number","string","boolean","object","function","undefined" 这6个值

2. instanceof 运算符

  对于对象和数组这种数据,利用typeof不能区分,这时候需要用到instanceof 运算符

var o = {};
var a = []; o instanceof Array // false
a instanceof Array // true

最新文章

  1. List转MVC DropDownListFor(SelectList)
  2. ASP.NET文件上传大小的限制解决方案
  3. Java throw:异常的抛出怎么回事
  4. C++中string 的使用
  5. 第三篇、C_双向链表(循环链表)
  6. uvalive 5760 Alice and Bob (组合游戏,dp)
  7. 《APUE》-第五章标准IO库
  8. 菜鸟的jQuery源码学习笔记(前言)
  9. CSS排序工具csscomb
  10. java 制作QQ登录界面
  11. List集合就这么简单【源码剖析】
  12. 【IOS 开发】Object-C 入门 Xcode 环境详解
  13. 前端——JavaScript之if语句
  14. Linux命令:popd
  15. MySQL root密码忘记,原来还有更优雅的解法!
  16. Scala进阶之路-idea下进行spark编程
  17. LeetCode题解之Convert Sorted List to Binary Search Tree
  18. 【chrome】安装证书并配置为受信任网站连接(windows)
  19. 大纲2.3 Internet
  20. elk +redis 环境搭建

热门文章

  1. 转贴 使用正则表达式解析一般sql语句(C++)
  2. 《视觉SLAM十四讲》第1讲
  3. Hibernate3核心API-SchemaExport类
  4. 微信小程序开发工具下载以及安装教程
  5. redis(2)事务的订阅与发布
  6. Python——PYQT:控件基本使用
  7. Spring RedisTemplate常用方法(List,Hash)
  8. jdk1.8-stack 栈源码分析
  9. Go语言集成开发工具JetBrains GoLandMac2.3中文版
  10. 模块的概念、模块的导入方式【IMPORT 模块名、FROM 模块 IMOPRT 功能】、模块的搜索路径、链式导入&循环导入