JAVASCRIPT-数据类型

February 24, 2026

数据类型

  • 数值(number)
  • 字符串 (string)
  • 布尔值(boolean)
  • undefined
  • null
  • 对象(object), 基本对象、数组、函数
  • symbol
  • 大整数(BigInt)

数据类型判断

  • typeof
  • instanceof
  • Object.prototype.toString

typeof 运算符

typeof 12 // "number" typeof "abc" // "string" typeof true // "boolean" typeof {} // "object" typeof [] // "object" typeof f(){} // "function" typeof undefined // "undefined" typeof可以用来检查一个没有声明的变量,而不报错。 typeof null // "object"

布尔值(boolean)

以下数据转换为布尔值为false,其他转为true

0 // false NaN // false "" // false '' //fasle fasle // false undefined //false null //false

typeof null

null 设计存储时,以全是0的二进制形式存储,typeof 判断时是按照二进制的形式判断的,以000开头的就是object