你不知道的js(中卷) 第一章类型

2018-11-29  本文已影响0人  土豪码农

一. 类型

六种基本类型,老生常谈了,但是es6加入了新的基本类型是symbol符号,后六种用typeof都能检测数据类型

要注意的点:

typeof null === 'object'  //true 这个基本都知道了,最基础的东西了
console.log(typeof function a() {a, b}); //function

函数不仅是对象,还也可以拥有属性,例如上述的函数a

console.log(a.length) //2 因为有两个匿名参数,所以length等于2

undefined 和 is not defined

声明了变量,但是没有赋值,则为undefined,未声明的变量直接引用则为is not defined,这个会导致浏览器报错

有个注意点:

var a
console.log(typeof a); //undefined
console.log(typeof b); //undefined b没有声明,也没有报错,依旧返回undefined,这是因为typeof有一个特殊的安全防范
上一篇 下一篇

猜你喜欢

热点阅读