内置类型
JS中分为七种内置类型,七种内置类型又分为两大类型:基本型和对象(Object).
基本类型有六种:null
,undefined
,boolean
,number
,string
,symbol
.
其中JS的数字类型是浮点型的,没有整型.而且浮点型基于IEEE754标准实现,在使用中会遇到某些Bug
.NaN
也属于number
类型,并且NaN
不等于自身.
对于基本类型来说,如果使用字面量的方式,那么这个变量只是个字面量,只有在必要的时候才会转换为对应的类型.
let a = 111;//这只是字面量,不是number类型
a.toString()//使用时候才会转换为对象类型
对象(Object)是引用类型,在使用过程中会遇到浅拷贝和深拷贝的问题.
let a={name:"FE"};
let b=a;
b.name="EF";
console.log(a.name);//EF
Typeof
typeof
对于基本类型,除了null
(显示object)都可以显示正确的类型.
typeof 1//'number'
typeof '1'//string
typeof undefined //'undefined'
typeof true //'boolean'
type Symbol()//'symbol'
typeof b//b没有声明,但是还会显示undefined
typeof
对于对象,除了函数都会显示object
typeof []//'Object'
typeof {}//'object'
typeof console.log//'function'