首页 > 设计 > WEB开发 > 正文

js数据类型

2019-11-02 18:22:21
字体:
来源:转载
供稿:网友
字符串(String)数字(Number)布尔(Boolean)数组(Array)对象(Object)空(Null)未定义(Undefined)var num = 1, boo = true, aa = null, bb, str = 'mary', arr = [1, 2, 4, 8], obj = { 'name': 'aa' }, arrNew = new Array([1, 2, 3]), strNew = new String([1, 2, 3]);// 用 typeof 检测变量的类型 console.log('Number:', typeof num); // numberconsole.log('Boolean:', typeof boo); // booleanconsole.log('Undefined:', typeof bb); // undefinedconsole.log('String:', typeof str); // stringconsole.log('Null:', typeof aa); // objectconsole.log('Array:', typeof arr); // objectconsole.log('Object:', typeof obj); // objectconsole.log('new Array():', typeof arrNew); // objectconsole.log('new String():', typeof strNew); // object// null 和 undefined 比较console.log(null == undefined); // trueconsole.log(null === undefined); // false

1、new 关键字声明的变量,得到的 都是一个对象 2、null:表示什么也没有,一个空对象引用 undefined:表示一个没有设置值的变量


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表