ECMAScript 버전별 주요 문법
아래는 ES5부터 최근 사양까지, 실제 사용에 영향이 큰 문법/내장 객체 변화만 간결히 추린 목록입니다. 간단 예제와 함께 정리했습니다.
ES5 (2009)
- 엄격 모드:
'use strict' - JSON:
JSON.parse,JSON.stringify - 배열 메서드:
forEach,map,filter,reduce,some,every
'use strict';
[1, 2, 3].map((n) => n * 2);
ES6 / ES2015
- 변수:
let,const - 함수: 화살표 함수, 기본값 매개변수, 나머지 매개변수
- 구조: 클래스, 모듈(
import/export) - 문법: 템플릿 리터럴, 비구조화 할당, 스프레드
- 컬렉션/반복:
Map,Set,for...of, 이터러블/제너레이터 - Promise, 심볼
const add = (a = 0, b = 0) => a + b;
const user = { id: 1, name: 'Lee' };
const { name } = user;
// import something from './mod.js'; (모듈 환경에서 사용)
ES2016
- 지수 연산자:
** Array.prototype.includes
2 ** 10; // 1024
[1, 2, 3].includes(2); // true
ES2017
async/awaitObject.values,Object.entries- 문자열 패딩:
padStart,padEnd
async function main() {
const res = await fetch('/api');
return res.ok;
}
ES2018
- 비동기 반복:
for await...of - 객체 Rest/Spread
Promise.prototype.finally
const { a, ...rest } = { a: 1, b: 2 };
await Promise.resolve();
Promise.resolve().finally(() => {});
ES2019
Array.prototype.flat,flatMapObject.fromEntriesString.prototype.trimStart,trimEnd
[['a'], ['b']].flat(); // ['a','b']
Object.fromEntries([['a', 1]]); // { a: 1 }
ES2020
- 옵셔널 체이닝
?., 널 병합?? Promise.allSettledglobalThisBigInt
const title = post?.meta?.title ?? 'untitled';
ES2021
String.prototype.replaceAll- 논리 할당 연산자:
||=,&&=,??= - 숫자 구분자:
1_000_000 Promise.any
obj.name ||= 'default';
ES2022
Array.prototype.atObject.hasOwn- 클래스 필드/정적 초기화 블록
- 최상위 await (모듈)
const last = arr.at(-1);
if (Object.hasOwn(obj, 'key')) {
}
ES2023
- 불변 복사 메서드:
toReversed,toSorted,toSpliced,with - 검색:
findLast,findLastIndex - Hashbang
#!/usr/bin/env node
const sorted = nums.toSorted((a, b) => a - b);
ES2024 (최근 사양)
- 그룹핑:
Array.prototype.group,groupToMap - 정규식
v플래그 (세트 표기 등 향상) Set메서드 확장:isSubsetOf,isSupersetOf,intersection,union,difference,symmetricDifferencePromise.withResolvers
const groups = ['a', 'ab', 'b'].group((s) => s[0]);
const { promise, resolve, reject } = Promise.withResolvers();
resolve(1);