JS学习笔记--变量类型

1.js数据类型分为基本数据类型和引用数据类型

    基本数据类型:string、number、boolean、null、undefined、symbol(ES6中新增)

    引用数据类型:object、array、function

2.判断数据类型的方法:

    2.1 typeof

        2.1.1 基本数据类型

            typeof string  ==>  string

            typeof number  ==>  number 

            typeof boolean  ==>  boolean

            typeof undefined  ==>  undefined

            typeof symbol () ==>  symbol

            typeof null  ==>  object

        2.1.2  引用数据类型

            typeof object  ==>  object

            typeof array  ==>  object

            typeof function  ==>  function

备注:

        1. typeof null 返回 object,这是typeof的一个不足(或者说是bug),null是基本数据类型,非引用类型;

        2.typeof [1,2,3] 返回object,返回的结果中不存在array,引用类型的数据除了function返回function之外,类外两种类型均返回object

        3.typeof symbol()返回  symbol,typeof symbol返回  function

猜你喜欢

转载自www.cnblogs.com/wifepig/p/9781644.html