![[红脸]](http://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/img/jj_emoji_63.c32f5b5.png)
day11 ES11
// 01_新增可选链? 当属性不存在时 直接返回undefined 避免报错
let text = {
name: "text",
address: {
title: "北京",
},
foo() {
console.log("方法存在");
return "foo";
},
};
const addTit = text?.address?.title;
console.log(addTit);
console.log(text?.foo?.());
// 02_新增空位合并操作符?? 当 ?? 前面的值为null或undefined时 使用后面的值
let yourname = "jame";
let kind = yourname ?? "詹姆斯";
console.log(kind);
// 03_新增globalThis 用于获取全局变量 多用于非全局作用域下获取全局作用域
console.log(globalThis); // window
console.log(this === globalThis); // true
// 04_BigInt表示大数字
let theBiggestNum = Number.MAX_SAFE_INTEGER;
// 超过最大值的数字不可预期 可能正确也可能不正确
console.log(theBiggestNum, theBiggestNum + 1, theBiggestNum + 2); //9007199254740991 9007199254740992 9007199254740992
// 数字后面 加上 n 标志为BigInt
let theBiggestNumMore = BigInt(theBiggestNum) + BigInt(2);
// 01_新增可选链? 当属性不存在时 直接返回undefined 避免报错
let text = {
name: "text",
address: {
title: "北京",
},
foo() {
console.log("方法存在");
return "foo";
},
};
const addTit = text?.address?.title;
console.log(addTit);
console.log(text?.foo?.());
// 02_新增空位合并操作符?? 当 ?? 前面的值为null或undefined时 使用后面的值
let yourname = "jame";
let kind = yourname ?? "詹姆斯";
console.log(kind);
// 03_新增globalThis 用于获取全局变量 多用于非全局作用域下获取全局作用域
console.log(globalThis); // window
console.log(this === globalThis); // true
// 04_BigInt表示大数字
let theBiggestNum = Number.MAX_SAFE_INTEGER;
// 超过最大值的数字不可预期 可能正确也可能不正确
console.log(theBiggestNum, theBiggestNum + 1, theBiggestNum + 2); //9007199254740991 9007199254740992 9007199254740992
// 数字后面 加上 n 标志为BigInt
let theBiggestNumMore = BigInt(theBiggestNum) + BigInt(2);
展开
评论
点赞