자바스크립트 ES2020 버전에서의 변화를 알아본다
globalThis
globalThis 를 이용해서 전역객체를 참조할 수 있게 되었다.
| 1
 | console.log(globalThis);
 | 
![globalThis]()
Promise.allSettled
Promise 를 멀티로 사용할 때 쓴다.
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 
 | const promise1 = new Promise((resolve, reject) => {resolve('First Promise was resolved');
 });
 const promise2 = new Promise((resolve, reject) => {
 reject('Second Promise was rejected');
 });
 const promise3 = new Promise((resolve, reject) => {
 resolve('Third Promise was resolved');
 });
 
 Promise.allSettled([promise1, promise2, promise3])
 .then((result) => console.log(result))
 .catch((err) => console.log(err));
 
 | 
![Promise.allSettled]()
Optional Chaining
?. 개인적으로 제일 유용할 것 같은 기능입니다.
속성이 있는지를 확인해줍니다
속성이 없으면 Error 가 나는 것을 Error 가 나지않고 undefined 을 Return 해줍니다.
메소드도 Optional Chaining 이 가능합니다.
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 
 | const ecom = {companyName: 'Coupang',
 year: 2021,
 country: 'Korea',
 intro() {
 return this.companyName + this.year;
 },
 };
 
 console.log(ecom.intro());
 console.log(ecom.outro?.());
 console.log(ecom.outro());
 
 | 
![Optional Chaining]()
BigInt
Int 보다 더 큰 정수를 사용할 수 있다
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 
 | let maxInt = Number.MAX_SAFE_INTEGER;console.log(maxInt);
 
 console.log(++maxInt);
 console.log(++maxInt);
 console.log(++maxInt);
 console.log(typeof maxInt);
 
 let maxInt2 = Number.MAX_SAFE_INTEGER;
 let bigInt = BigInt(maxInt2);
 console.log(bigInt);
 
 console.log(++bigInt);
 console.log(++bigInt);
 console.log(++bigInt);
 console.log(typeof bigInt);
 
 | 
![BigInt]()
연관포스트