JS中 typeof 运算符

默认分类 · 2021-09-03
  • typeof 是一个运算符
  • typeof 返回一个值的数据类型

typeof 100   // "number"
typeof "ABC" // "string"
typeof true  // "boolean"
typeof function(){} // "function"
typeof []  // "object"
typeof {} // "object"
typeof undefined  //"undefined"
typeof $var // "undefined"

数组([])和对象({})的返回值都是"object",怎么区分呢?

Array.isArray([])  // true
js
Theme Jasmine by Kent Liao