๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Develop ๐Ÿ’ป/JavaScript

[JavaScript] ES7 - 12 ๋ฌธ๋ฒ• / ECMAScript 2016 ~ 2021

by jungin 2021. 7. 25.

Intro


๋ถ„๋ช… JS๋ฅผ ์“ฐ๊ณ  ์žˆ๋Š”๋ฐ C์–ธ์–ด์Šค๋Ÿฝ๊ฒŒ ์ฝ”๋”ฉํ•˜๋Š” ๋‚ด ์ž์‹ ์„ ๋ฐœ๊ฒฌํ•˜์—ฌ ์ด๋ ‡๊ฒŒ ์ตœ์‹  ๋ฌธ๋ฒ•์„ ์ •๋ฆฌํ•ด๋ณธ๋‹ค ! (์ฃผ์š”ํ•œ ๊ฒƒ๋งŒ)

 

ES7(2016)

1. Array.prototype.includes()

๋ฐฐ์—ด ๋‚ด์— ๊ฐ’์ด ์žˆ๋Š”์ง€ ์—†๋Š”์ง€ ํ™•์ธ

๊ฐ’์ด ์žˆ์œผ๋ฉด True, ์—†์œผ๋ฉด false ๋ฅผ ๋ฐ˜ํ™˜

assert([1, 2, 3].includes(2) === true);
assert([1, 2, 3].includes(4) === false);

assert([1, 2, NaN].includes(NaN) === true);

assert([1, 2, -0].includes(+0) === true);
assert([1, 2, +0].includes(-0) === true);

assert(["a", "b", "c"].includes("a") === true);
assert(["a", "b", "c"].includes("a", 1) === false);

 

2. Exponentiation Operator(์ œ๊ณฑ์—ฐ์‚ฐ์ž)

let cubed = 2 ** 3;
// same as: 2 * 2 * 2

let a = 2;
a **= 2;
// same as: a = a * a;

let b = 3;
b **= 3;
// same as: b = b * b * b;

ES8(2017)

1.Object.values / Object.entries

values ๋งค์†Œ๋“œ๋Š” ๊ฐ์ฒด ๋‚ด ๋ชจ๋“  value ๊ฐ’๋“ค์„ ๋ฐฐ์—ด ํ˜•ํƒœ๋กœ ๋ฐ˜ํ™˜

entries ๋ฉ”์†Œ๋“œ๋Š” ๊ฐ์ฒด ๋‚ด key,value๋ฅผ ๋ฌถ์–ด์„œ ๋ฐฐ์—ด ํ˜•ํƒœ๋กœ ๋ฐ˜ํ™˜

const dimigoin = {
  name: "๊น€์ •์ธ",
  age: 18,
  class: 4,
};

Object.values(dimigoin); // ["๊น€์ •์ธ", 18, 4]
Object.entries(dimigoin);// [["name", "๊น€์ •์ธ"],["age", 18],["class", 4]]

 

2.String Padding

๋ฌธ์ž์—ด์— ์—ฌ๋ฐฑ or ๋ฌธ์ž๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉ”์†Œ๋“œ padStart , padEnd

str.padStart(targetLength, padString) // ์•ž
str.padEnd(targetLength, padString) // ๋’ค
//targetLength : ๋ชฉํ‘œ ๋ฌธ์ž์—ด ๊ธธ์ด, ํ˜„์ž ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋ณด๋‹ค ์ž‘๋‹ค๋ฉด ๊ฐ’ ๊ทธ๋Œ€๋กœ ๋ฐ˜ํ™˜
//padString: ํ˜„์žฌ ๋ฌธ์ž์—ด์— ์ฑ„์›Œ๋„ฃ์„ ๋‹ค๋ฅธ ๋ฌธ์ž์—ด. ๊ธฐ๋ณธ๊ฐ’์€ ""
//return ๊ฐ’ : ๋ฐ”๋€ ๋ฌธ์ž์—ด

'abc'.padStart(10);         // "       abc"
'abc'.padStart(10, "foo");  // "foofoofabc"
'abc'.padStart(6,"123465"); // "123abc"
'abc'.padStart(8, "0");     // "00000abc"
'abc'.padStart(1);          // "abc"

'abc'.padEnd(10);          // "abc       "
'abc'.padEnd(10, "foo");   // "abcfoofoof"
'abc'.padEnd(6, "123456"); // "abc123"
'abc'.padEnd(1);           // "abc"

 

3.Object.getOwnPropertyDescriptors

๊ธฐ์กด์— ์กด์žฌํ•˜๋˜ Object.getOwnPropertyDescriptor์— s๊ฐ€ ๋ถ™์Œ

๊ธฐ์กด Object.getOwnPropertyDescriptor๋Š” ๊ฐ์ฒด์™€ ์†์„ฑ๋ช…์„ ์ธ์ž๋กœ ๋ฐ›์•„์„œ ํ•ด๋‹น ์†์„ฑ์˜ ์†์„ฑ ์„ค๋ช…์ž๋ฅผ ๋ฐ˜ํ™˜

Object.getOwnPropertyDescriptors๋Š” ๊ฐ์ฒด๋งŒ ์ธ์ž๋กœ ๋ฐ›์•„ ํ•ด๋‹น ๊ฐ์ฒด ๋‚ด ์ž์‹ ์˜ ๋ชจ๋“  ์†์„ฑ ์„ค๋ช…์ž๋ฅผ ๋ฐ˜ํ™˜

const dimigoin = {
  name: "๊น€์ •์ธ",
  age: 18,
  class: 4,
};

console.log(Object.getOwnPropertyDescriptor(dimigoin,"name"));
//{value: "๊น€์ •์ธ", writable: true, enumerable: true, configurable: true}
console.log(Object.getOwnPropertyDescriptors(dimigoin));
//{name: {…}, age: {…}, class: {…}}
//age: {value: 18, writable: true, enumerable: true, configurable: true}
//class: {value: 4, writable: true, enumerable: true, configurable: true}
//name: {value: "๊น€์ •์ธ", writable: true, enumerable: true, configurable: true}
//__proto__: Object

 

4.Trailing commas(final commas)

javascript๋Š” ์ดˆ๊ธฐ๋ถ€ํ„ฐ ๋ฐฐ์—ด์— final commas๊ฐ€ ํ—ˆ์šฉ๋˜์—ˆ๋‹ค ! ES8๋ถ€ํ„ฐ๋Š” ํ•จ์ˆ˜์˜ ๋งค๊ฐœ๋ณ€์ˆ˜์—๋„ ํ—ˆ์šฉํ•˜๊ธฐ ์‹œ์ž‘ํ•จ ! ๋‹จ JSON์—์„œ๋Š” ํ—ˆ์šฉ๋˜์ง€ ์•Š์Œ

final commas๋ฅผ ์“ฐ๋ฉด ์ƒˆ๋กœ์šด ์—˜๋ฆฌ๋จผํŠธ,๋งค๊ฐœ๋ณ€์ˆ˜,์†์„ฑ์„ ์ถ”๊ฐ€ํ•  ๋•Œ ์œ ์šฉํ•˜๊ณ  ์ˆ˜์ • ์—†์ด ๋ณต์‚ฌํ•ด์„œ ์“ธ ์ˆ˜ ์žˆ์Œ ! ์ด ์™ธ์—๋„ ๋ฒ„์ „ ๊ด€๋ฆฌ ์ด๋ ฅ์ด ๊ฐ„๋‹จํ•˜๊ณ  ์ฝ”๋“œ ํŽธ์ง‘์ด ๋” ํŽธํ•ด์ง„๋‹ค๋Š” ์žฅ์ ์ด ์žˆ๋‹จ๋‹ค ~

//Array
var arr = [
  1,
  2,
  3,
];

//Object
var object = {
  foo: "bar",
  baz: "qwerty",
  age: 42,
};
//function parameter, argument
//์•„๋ž˜ ๋ฌถ์ธ ์ฝ”๋“œ๋Š” ๋ชจ๋‘ ์œ ํšจํ•˜๋ฉฐ ์„œ๋กœ ๊ฐ™์Œ
function f(p) {}
function f(p,) {}

f(p);
f(p,);

Math.max(10, 20);
Math.max(10, 20,);

 

5.Async Functions

๋น„๋™๊ธฐ ํ•จ์ˆ˜ ! , Promise๋ฅผ ๋”์šฑ ์‰ฝ๊ฒŒ ๋‹ค๋ฃจ๊ณ  ์ฝ”๋“œ๋ฅผ ๊น”๋”ํ•˜๊ฒŒ ์งœ๊ธฐ ์œ„ํ•ด async,await ๋„์ž… ! but ์ด ๋‚ด์šฉ์€ ๋”ฐ๋กœ ๋น„๋™๊ธฐ ์ชฝ์—์„œ ๋‹ค๋ฃจ๊ฒ ์Œ !

ES9(2018)

1.Rest/Spread Properties(๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด์—์„œ์˜ ์ „๊ฐœ)

๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด์—์„œ๋„ ์ „๊ฐœ ๊ตฌ๋ฌธ์ด ๊ฐ€๋Šฅํ•ด์ง !

์ „๊ฐœ ๊ตฌ๋ฌธ์ด๋ž€?

๋ฐฐ์—ด์ด๋‚˜ ๋ฌธ์ž์—ด๊ณผ ๊ฐ™์€ iterable(๋ฐ˜๋ณต ๊ฐ€๋Šฅ)ํ•œ Object๋ฅผ ๋ง ๊ทธ๋Œ€๋กœ ์ „๊ฐœํ•จ ! ์ฝ”๋“œ๋ฅผ ๋ณด๊ณ  ์ดํ•ดํ•˜๋Š” ๊ฒŒ ๋” ๋น ๋ฅผ ๋“ฏ

const num =[1,2,3]
console.log(...num) //1 2 3

//ํ•จ์ˆ˜ ํ˜ธ์ถœ์—์„œ์˜ ์ „๊ฐœ
function myFunction(x, y, z) {}
var args = [0, 1, 2];
myFunction(...args);

//๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด์—์„œ์˜ ์ „๊ฐœ(ES9 ์ถ”๊ฐ€)
var obj1 = { foo: 'bar', x: 42 };
var obj2 = { foo: 'baz', y: 13 };

var clonedObj = { ...obj1 };
// Object { foo: "bar", x: 42 }

var mergedObj = { ...obj1, ...obj2 };
// Object { foo: "baz", x: 42, y: 13 }

 

2.Promise.prototype.finally

promise์— finally๊ณผ ์ถ”๊ฐ€ ๋จ ! ๊ธฐ์กด์—” then ๊ณผ catch๋งŒ ์žˆ์—ˆ์œผ๋‚˜ finally๋Š” ์„ฑ๊ณต ์—ฌ๋ถ€์— ๊ด€๊ณ„์—†์ด promise ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•จ.

let isLoading = true;

fetch(myRequest).then(function(response) {
    var contentType = response.headers.get("content-type");
    if(contentType && contentType.includes("application/json")) {
      return response.json();
    }
    throw new TypeError("Oops, we haven't got JSON!");
  })
  .then(function(json) { /* process your JSON further */ })
  .catch(function(error) { console.log(error); })
  .finally(function() { isLoading = false; });

 

3.Asynchronous Iteration

๋‚˜์ค‘์— ๋‹ค์‹œ ์ดํ•ดํ•ด์„œ ์“ธ ์˜ˆ์ •.. ๋„ˆ๋ฌด ์–ด๋ ต์ž๋„ˆ,,

ES10(2019)

1.Optional catch binding

try,catch ๊ตฌ๋ฌธ์„ ์“ธ ๋•Œ ์›๋ž˜ catch์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ๊ผญ ์žˆ์–ด์•ผ ํ–ˆ์ง€๋งŒ ES10 ๋ถ€ํ„ฐ ์„ ํƒ์ ์œผ๋กœ ๋ฐ”๋€œ !

try {
  doSomethingThatMightThrow();
} catch (exception) {
  //     ^^^^^^^^^
  // We must name the binding, even if we don’t use it!
  handleException();
}
//ES10
try {
  doSomethingThatMightThrow();
} catch { // → No binding!
  handleException();
}

 

2.Symbol.prototype.description

์ด์ „์— Symbol์˜ ๋‚ด์šฉ์„ ๋ณด๋ ค๋ฉด ์ด๋Ÿฌํ•œ ์ฝ”๋“œ๋ฅผ ์งœ์•ผ ๋ฌ์Œ

const symbol = Symbol('foo');
//                    ^^^^^
symbol.toString();
// → 'Symbol(foo)'
//           ^^^
symbol.toString().slice(7, -1); // ๐Ÿค”
// → 'foo'

๊ทธ๋Ÿฌ๋‚˜ ์ด๊ฒƒ์€ ํ•œ ๋ˆˆ์— ๋ด๋„ ๋ณ„๋กœ์ž„. ๊ทธ๋ž˜์„œ Symbol.prototype.description์„ ๋„์ž… !

const symbol = Symbol('foo');
//                    ^^^^^
symbol.description;
// → 'foo'

 

3.Object.fromEntries()

ES8์—์„œ ๋„์ž…๋œ Object.entries์™€ ํ˜ธํ™˜๋˜๋Š” ๋ฉ”์†Œ๋“œ์ž„ ! entries๋ฅผ ํ†ตํ•ด ๋งŒ๋“ค์–ด์ง„ ๋ฐฐ์—ด์„ ์ธ์ž๋กœ ๋ฐ›์•„ ๋‹ค์‹œ ๊ฐ์ฒด๋กœ ๋งŒ๋“ค์–ด์คŒ

const dimigoin = {
  name: "๊น€์ •์ธ",
  age: 18,
  class: 4,
};
const entries = Object.entries(dimigoin)
const fromEntries = Object.fromEntries(entries)
console.log(fromEntries) //{name: "๊น€์ •์ธ", age: 18, class: 4}

 

4.String.prototype.trimStart()/trimEnd()

๋ฌธ์ž์—ด์˜ ์•ž , ๋’ค ๊ณต๋ฐฑ์„ ์ œ๊ฑฐํ•ด์คŒ. trimStart๋Š” trimLeft๋กœ, trimEnd๋Š” trimRight๋ผ๋Š” ๋ณ„์นญ์œผ๋กœ ์“ธ ์ˆ˜ ์žˆ์Œ. 

const greeting = '   Hello world!   ';

console.log(greeting.trimStart());
// expected output: "Hello world!   ";

console.log(greeting.trimEnd());
// expected output: '   Hello world!';

 

5.Array.prototype.flat()

flat() ๋ฉ”์„œ๋“œ๋Š” ๋ชจ๋“  ํ•˜์œ„ ๋ฐฐ์—ด ์š”์†Œ๋ฅผ ์ง€์ •ํ•œ ๊นŠ์ด๊นŒ์ง€ ์žฌ๊ท€์ ์œผ๋กœ ์ด์–ด๋ถ™์ธ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

๋˜ํ•œ ๋ฐฐ์—ด์˜ ๊ตฌ๋ฉ๋„ ์ œ๊ฑฐํ•จ

const arr1 = [1, 2, [3, 4]];
arr1.flat();
// [1, 2, 3, 4]

const arr2 = [1, 2, [3, 4, [5, 6]]];
arr2.flat();
// [1, 2, 3, 4, [5, 6]]

const arr3 = [1, 2, [3, 4, [5, 6]]];
arr3.flat(2);
// [1, 2, 3, 4, 5, 6]

const arr4 = [1, 2, [3, 4, [5, 6, [7, 8, [9, 10]]]]];
arr4.flat(Infinity);
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

const arr5 = [1, 2, , 4, 5];
arr5.flat();
// [1, 2, 4, 5]

 

6.Array.prototype.flatMap()

flat์™€ Map ํ•จ์ˆ˜๋ฅผ ํ•ฉ์นœ๊ฑฐ๋ผ ๋ณด๋ฉด ๋จ ! ๋จผ์ € ๋ฐฐ์—ด์˜ ๊ฐ ์—˜๋ฆฌ๋จผํŠธ์— map ์ˆ˜ํ–‰ ํ›„ ์œ„์— flat์„ ์ˆ˜ํ–‰ ! (1 depth๋งŒ)

let arr1 = [1, 2, 3, 4];

arr1.map(x => [x * 2]);
// [[2], [4], [6], [8]]

arr1.flatMap(x => [x * 2]);
// [2, 4, 6, 8]

// ํ•œ ๋ ˆ๋ฒจ๋งŒ ํ‰ํƒ„ํ™”๋จ
arr1.flatMap(x => [[x * 2]]);
// [[2], [4], [6], [8]]

ES11(2020)

1.Optional chaining(?.)

์ฐธ์กฐ๋ฅผ ํ•  ๋•Œ ๊ฐ’์ด ์žˆ๋Š” ์ง€ ์—†๋Š” ์ง€ ๊ฒ€์ฆํ•  ๋•Œ Optional chaining์„ ์“ฐ๋ฉด ์ฐธ์กฐ๊ฐ€ null or undefined์ผ ๋•Œ ์—๋Ÿฌ ๋Œ€์‹  undefined๋ฅผ ๋ฐ˜ํ™˜ํ•ด์คŒ ! (๊ฐœ์ธ์ ์œผ๋กœ react ํ”„๋กœ์ ํŠธ ํ•  ๋•Œ ์˜ค๋ฅ˜ ์•ˆ ๋‚˜์„œ ์ •๋ง ์š”๊ธดํ•˜๊ฒŒ ์‚ฌ์šฉ ์ค‘ !)

//default
const dimigoin = {
  name: "๊น€์ •์ธ",
  age: 18,
  class:4,
  personality:{
      habit:"sports"
  }
};

const dimigoin2= {
    name:"์žฅ์ •์ธ",
    age:18,
    class:4
}

function printClass(person){
    console.log(person.personality.habit)
}
printClass(dimigoin) //sports
printClass(dimigoin2) //error

//Optional Chaining

const dimigoin = {
  name: "๊น€์ •์ธ",
  age: 18,
  class:4,
  personality:{
      habit:"sports"
  }
};

const dimigoin2= {
    name:"์žฅ์ •์ธ",
    age:18,
    class:4
}

function printClass(person){
    console.log(person?.personality?.habit)
}
printClass(dimigoin) //sports
printClass(dimigoin2) //undefined

 

2.Nullish coalescing Operator

์ฃผ๋กœ ๊ธฐ๋ณธ๊ฐ’์„ ํ• ๋‹นํ•  ๋–„ || ์—ฐ์‚ฐ์ž๋ฅผ ํ™œ์šฉํ–ˆ์Œ ! BUT, 0,' ' ๊ฐ™์€ ๊ฐ’๋“ค์ด ๋“ค์–ด๊ฐˆ ๋•Œ ์˜๋„๋Œ€๋กœ ์ž‘๋™ํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Œ !

//์‚ฌ์šฉ์ž๋Š” ์ต๋ช…์„ ์›ํ•จ
const name =' '
const userName = name || 'Guest'
console.log(userName) //Guest

//์‚ฌ์šฉ์ž๋Š” 0์ด๋ผ๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ์›ํ•จ
const num = 0;
const message = num || 'undefined'
console.log(message) //undefined

Nullish coalescing Operator๋ฅผ ์ด์šฉํ•˜๋ฉด ๊ฐ’์ด Null ์ด๋‚˜ undefined์ธ ๊ฒฝ์šฐ์—๋งŒ ๊ธฐ๋ณธ ๊ฐ’์„ ํ• ๋‹นํ•ด์ค„ ์ˆ˜ ์žˆ์Œ ! ์•ž์œผ๋กœ or ์—ฐ์‚ฐ์ž ๋ณด๋‹ค๋Š” Nullish coalescing Operator๋ฅผ ์• ์šฉํ•˜์ž !

//์‚ฌ์šฉ์ž๋Š” ์ต๋ช…์„ ์›ํ•จ
const name =' '
const userName = name ?? 'Guest'
console.log(userName) //

//์‚ฌ์šฉ์ž๋Š” 0์ด๋ผ๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ์›ํ•จ
const num = 0;
const message = num ?? 'undefined'
console.log(message) // 0

 

3.globalThis

๊ธฐ์กด์—๋Š” js ์‹คํ–‰ํ™˜๊ฒฝ์— ๋”ฐ๋ผ์„œ global ๊ฐ์ฒด์— ์ ‘๊ทผํ•˜๋Š ๋ฐฉ๋ฒ•์ด ๋‹ฌ๋ž์Œ

๋ธŒ๋ผ์šฐ์ €์—์„œ๋Š” window,self,frame ์‚ฌ์šฉ, ๋…ธ๋“œ์—์„œ๋Š” global, Web Worker*(Web Worker๋Š” script ์‹คํ–‰์„ ๋ฉ”์ธ ์“ฐ๋ ˆ๋“œ๊ฐ€ ์•„๋‹ˆ๋ผ ๋ฐฑ๊ทธ๋ผ์šด๋“œ ์“ฐ๋ ˆ๋“œ์—์„œ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ฃผ๋Š” ๊ธฐ์ˆ  ์ž…๋‹ˆ๋‹ค.)์—์„œ๋Š” self๋ฅผ ํ†ตํ•ด์„œ ์ ‘๊ทผํ–ˆ์—ˆ์Œ.*

But ์ด์ œ๋Š” globalThis๋ฅผ ์ด์šฉํ•˜๋ฉด ๋ชจ๋“  ํ™˜๊ฒฝ์—์„œ ์ ‘๊ทผ ๊ฐ€๋Šฅ

// ๋ธŒ๋ผ์šฐ์ € ์‹คํ–‰ ํ™˜๊ฒฝ ๊ธฐ์ค€
 globalThis === window // true

 

4.Dynamic import

Dynamic Import ๋Š” ์ผ๋ฐ˜์ ์ธ ์ •์ ์ธ Module Import ๋ฅผ ํ•„์š”ํ•œ ์‹œ์  ์— ๋กœ๋“œ ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์คŒ ! ์›น ํŽ˜์ด์ง€์— ์„ฑ๋Šฅ ์˜ฌ๋ฆฌ๊ธฐ ๊ฐ€๋Šฅ ! react ๊ฐ™์€ SPA์—์„œ ์“ฐ๋ฉด ์ข‹์„ ๋“ฏ??(์ฃผ๊ด€์  ์ƒ๊ฐ)

 

5.BigInt

BigInt๋Š” Number ์›์‹œ ๊ฐ’์ด ์•ˆ์ •์ ์œผ๋กœ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€์น˜์ธ 2^53 - 1๋ณด๋‹ค ํฐ ์ •์ˆ˜๋ฅผ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋Š” ๋‚ด์žฅ ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค.

BigInt๋Š” ์ •์ˆ˜ ๋ฆฌํ„ฐ๋Ÿด์˜ ๋’ค์— n์„ ๋ถ™์ด๊ฑฐ๋‚˜(10n) ํ•จ์ˆ˜ BigInt()๋ฅผ ํ˜ธ์ถœํ•ด ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

const theBiggestInt = 9007199254740991n;

const alsoHuge = BigInt(9007199254740991);
// โ†ช 9007199254740991n

const hugeString = BigInt("9007199254740991");
// โ†ช 9007199254740991n

const hugeHex = BigInt("0x1fffffffffffff");
// โ†ช 9007199254740991n

const hugeBin = BigInt("0b11111111111111111111111111111111111111111111111111111");
// โ†ช 9007199254740991n

 

5.String.prototype.matchAll

์ •๊ทœํ‘œํ˜„์‹ ๊ด€๋ จ์ธ๋ฐ ์•„์ง ์ •๊ทœํ‘œํ˜„์‹ ๊ณต๋ถ€๋ฅผ ์•ˆํ•ด์„œ ๋ชจ๋ฅด๋‹ˆ ์ถ”ํ›„์— ์“ฐ๊ฒ ์œผ,,

 

6.Promise.allSettled()

Promise.allSettled() ๋ฉ”์†Œ๋“œ๋Š” ๋ฐฐ์—ด์ด๋‚˜ ๋ณ„๋„์˜ ๋‚˜์—ด ๊ฐ€๋Šฅํ•œ ๊ฐ์ฒด๋ฅผ ํ†ตํ•ด ๋‚˜์—ด๋œ Promise๋ชจ์Œ์ด ๋ชจ๋‘ ์ดํ–‰ํ•˜๊ฑฐ๋‚˜ ๊ฑฐ๋ถ€ํ–ˆ์„ ๋•Œ์— ๋Œ€ํ•œ ๋Œ€์‘์„ ํ•  ์ˆ˜ ์žˆ๋Š” Promise ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

const promise1 = Promise.resolve(3);
const promise2 = new Promise((resolve, reject) => setTimeout(reject, 100, 'foo'));
const promises = [promise1, promise2];

Promise.allSettled(promises).
  then((results) => results.forEach((result) => console.log(result.status)));

// expected output:
// "fulfilled"
// "rejected"

ES11(2020)

1.String.prototype.replaceAll()

๊ธฐ์กด์— ์žˆ๋˜ replace์—์„œ ์ถ”๊ฐ€๋œ ๊ฒƒ์œผ๋กœ ๋ฌธ์ž์—ด์—์„œ ๋ฐ”๊ฟ€ ๋ฌธ์ž๋ฅผ ๋ชจ๋‘ ์ฐพ์•„ ์ƒˆ๋กœ์šด ๋ฌธ์ž๋กœ ๋ฐ”๊ฟ”์คŒ

const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';

console.log(p.replaceAll('dog', 'monkey'));
// expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"

 

2.Promise.any()

์–ด๋–ค promise ํ•˜๋‚˜๋ผ๋„ resolve ๋˜๋ฉด resovle ๋จ

const promise1 = Promise.reject(0);
const promise2 = new Promise((resolve) => setTimeout(resolve, 100, 'quick'));
const promise3 = new Promise((resolve) => setTimeout(resolve, 500, 'slow'));

const promises = [promise1, promise2, promise3];

Promise.any(promises).then((value) => console.log(value));

// expected output: "quick"

 

3.WeakRef

๋‚˜์ค‘์— ์“ธ๊ฒŒ์˜

 

4.Logical assignment operators

์ด์ œ (??, &&,||) ๋„ a += 2 ์ฒ˜๋Ÿผ ํ• ๋‹น ์—ฐ์‚ฐ์ž ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•จ

expr1 ||= expr2 // expr1 || expr2
expr1 &&= expr2 // expr1 && expr2
expr1 ??= expr2 // expr1 ?? expr2

 

5.Separators for numeric literals

์ด์ œ ํฐ ์ˆซ์ž ๊ตฌ๋ถ„์„ _๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ฐ€๋Šฅ !

const number = 1_000_000
const money = 1_000_000.123_456;
const octal = 0o123_123;

 

P.S : ๋…ธ์…˜์—์„œ๋Š” ์ตœ์‹  ๋ฌธ๋ฒ•์„ ๋‹ค ์ง€์›ํ•ด์คฌ๋Š”๋ฐ ํ‹ฐ์Šคํ† ๋ฆฌ ์ฝ”๋“œ ๋ธ”๋Ÿญ์€ ์ง€์›์„ ์•ˆ ํ•ด์ค€๋‹ค ใ… ใ…œ,,

๋Œ“๊ธ€