【JavaScript】数据类型
2021/09/08 18:15:29
最新的 ECMAScript 标准定义了 8 种数据类型:包括七个基本类型和一个引用类型
基本类型(基本数值、基本数据类型)是一种既非对象也无方法的数据。在 JavaScript 中,共有 7 种基本类型:string,number,bigint,boolean,null,undefined,symbol (ECMAScript 2016 新增)。
- undefined:
typeof instance === "undefined" - Boolean:
typeof instance === "boolean" - Number:
typeof instance === "number" - String:
typeof instance === "string - BigInt:
typeof instance === "bigint" - Symbol :
typeof instance === "symbol" - null:
typeof instance === "object"。 - Object:
typeof instance === "object"
记住 typeof 操作符的唯一目的就是检查数据类型,如果我们希望检查任何从 Object 派生出来的结构类型,使用 typeof 是不起作用的,因为总是会得到 "object"。