用来判断数据类型的两个方法

目录

一、typeof():判断简单数据类型

二、instanceof:判断复杂数据类型


一、typeof():判断简单数据类型

           简单数据类型:数值、字符串、符号、布尔值、null、undefined

用法:

let a=[1,2]

typeof(a)                //=====>Object

 

-----------------------------------------------------

let b={"npm":"wp"}

扫描二维码关注公众号,回复: 14617420 查看本文章

typeof(b)                  //========>Object

 

-----------------------------------------------------

let c="hhw"

typeof(c)                  //========>String

 

................

二、instanceof:判断复杂数据类型

          复杂数据类型:对象、数组

用法:

let a=[1,2]

a instanceof Array                 //=====>true 

a instanceof Object              //=====>true

 

 

---------------------------------------------------------

let b={"npm":"wp"}

b instanceof Object               //========>true

 

---------------------------------------------------------

let c="hhw"

c instanceof String               //========>false

 

................

猜你喜欢

转载自blog.csdn.net/qq_50276105/article/details/129725432