JavaScript---数据类型

数据类型

  • 基本数据类型(值类型):number;String;boolean;null;undefined
  • 引用数据类型
    • Object: {} [] /^$/ 日期对象 Math 实例对象
    • function
  • ES6中新增 Symbol 唯一值

NaN 是数值型
在这里插入图片描述
NaN = NaN 也是不相等的,和谁都不相等,所以检测是否为有效数字需要用isNaN

对象的属性名一定不能是引用类型值,默认会把引用类型值转换为字符

let a = {
            x: 100
        };
        let b = function fn() {
            let a = 100;
        }
        let obj = {
            0: 100,
            true: '珠峰'
        };
        obj[a] = 1000;
        obj[b] = 2000;
        console.log(obj);
        console.log(obj[a]);
        console.log(obj[0]);
        console.log(obj['0']);
        console.log(obj[true])
        console.log(obj['true']);

输出结果:
在这里插入图片描述

数组是特殊的对象
对象的属性是键值对,数组其实也可以看成键值对。
在这里插入图片描述

例题

let a = {};
b = '0';
c = 0;
a[b] = 'hello';
a[c] = 'world';
console.log(a[b]);

输出结果是world

let a = {};
b = Symbol('0');
c = Symbol('0');
a[b] = 'hello';
a[c] = 'world';
console.log(a[b]);

结果是 hello

let a = {};
b = {
    n: 1
};
c = {
    m: '2'
}
a[b] = 'hello';
a[c] = 'world';
console.log(a[b]);

结果是world

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值