ES2025(ECMAScript 2025) 개요

ECMAScript 2025(ES16)가 정식 릴리스되면서 JavaScript에 실용적인 기능들이 대거 추가되었다. 이번 업데이트는 오래된 불편함을 해소하는 데 초점을 맞추고 있으며, 특히 Set 연산, Iterator Helpers, Temporal API가 핵심이다.

1. Set 연산 메서드

드디어 Set에 수학적 집합 연산 메서드가 표준으로 추가되었다. 기존에는 배열로 변환하거나 직접 로직을 구현해야 했던 작업을 한 줄로 처리할 수 있다.

const frontend = new Set(["React", "Vue", "Svelte", "Angular"]);
const backend = new Set(["Express", "Fastify", "React", "Vue"]);

// 교집합: 프론트와 백엔드 모두에서 쓰이는 기술
frontend.intersection(backend);
// Set {"React", "Vue"}

// 합집합: 모든 기술
frontend.union(backend);
// Set {"React", "Vue", "Svelte", "Angular", "Express", "Fastify"}

// 차집합: 프론트에서만 쓰이는 기술
frontend.difference(backend);
// Set {"Svelte", "Angular"}

// 대칭 차집합: 한쪽에만 있는 기술
frontend.symmetricDifference(backend);
// Set {"Svelte", "Angular", "Express", "Fastify"}

// 부분집합 확인
const core = new Set(["React", "Vue"]);
core.isSubsetOf(frontend); // true
frontend.isSupersetOf(core); // true

// 서로소 확인 (공통 요소 없음)
const mobile = new Set(["Flutter", "Swift"]);
mobile.isDisjointFrom(frontend); // true

2. Iterator Helpers

Iterator Helpers는 배열뿐 아니라 모든 이터러블에 .map(), .filter(), .take() 등을 체이닝할 수 있게 해준다. 지연 평가(lazy evaluation) 방식으로 메모리 효율이 뛰어나다.

// 제너레이터에서 직접 체이닝
function* fibonacci() {
  let a = 0, b = 1;
  while (true) {
    yield a;
    [a, b] = [b, a + b];
  }
}

// 피보나치 수열에서 짝수만 10개 추출
const evenFibs = fibonacci()
  .filter(n => n % 2 === 0)
  .take(10)
  .toArray();
console.log(evenFibs);
// [0, 2, 8, 34, 144, 610, 2584, 10946, 46368, 196418]

// Map에서 활용
const users = new Map([
  ["user1", { name: "Kim", age: 28 }],
  ["user2", { name: "Lee", age: 35 }],
  ["user3", { name: "Park", age: 22 }]
]);

const seniorNames = users.values()
  .filter(user => user.age >= 30)
  .map(user => user.name)
  .toArray();
console.log(seniorNames); // ["Lee"]

// forEach와 reduce도 지원
users.values()
  .map(u => u.age)
  .reduce((sum, age) => sum + age, 0);
// 85

3. JSON 모듈 임포트

JSON 파일을 import 구문으로 직접 가져올 수 있게 되었다.

// 기존 방식 (Node.js)
import { readFileSync } from "fs";
const config = JSON.parse(readFileSync("./config.json", "utf-8"));

// ES2025 방식
import config from "./config.json" with { type: "json" };
console.log(config.database.host);

// 동적 import에서도 사용 가능
const pkg = await import("./package.json", { with: { type: "json" } });
console.log(pkg.default.version);

4. RegExp.escape()

사용자 입력을 정규식에 안전하게 포함시킬 수 있는 정적 메서드가 추가되었다. 정규식 인젝션 공격을 방지한다.

const userInput = "price: $100.00 (USD)";

// 기존: 직접 이스케이프 함수 작성 필요
// ES2025: 내장 메서드
const escaped = RegExp.escape(userInput);
console.log(escaped);
// "price\:\ \$100\.00\ \(USD\)"

const regex = new RegExp(escaped);
console.log(regex.test("price: $100.00 (USD)")); // true

// 실용 예: 사용자 검색어 하이라이트
function highlight(text, query) {
  const safe = RegExp.escape(query);
  return text.replace(new RegExp(safe, "gi"), "$&");
}
highlight("C++ is great", "C++");
// "C++ is great"

5. Promise.try()

동기/비동기 코드를 통일된 Promise 체인으로 감싸는 유틸리티가 추가되었다.

// 기존: 동기 에러가 catch에 잡히지 않는 문제
function getUser(id) {
  if (!id) throw new Error("ID required"); // 이건 catch에 안 잡힘
  return fetch(`/api/users/${id}`);
}

// 기존 해결책
Promise.resolve().then(() => getUser(null)).catch(console.error);

// ES2025: Promise.try()
Promise.try(() => getUser(null))
  .then(user => console.log(user))
  .catch(err => console.error(err.message));
// "ID required" - 정상적으로 catch됨

6. Temporal API (Stage 3, 곧 표준화)

JavaScript의 Date 객체를 대체하는 Temporal API가 Stage 3까지 진행되었다. 날짜/시간 처리의 모든 고질적인 문제를 해결한다.

// 현재 시각 (타임존 포함)
const now = Temporal.Now.zonedDateTimeISO();
console.log(now.toString());
// "2026-04-09T14:30:00+09:00[Asia/Seoul]"

// 특정 날짜 생성
const release = Temporal.PlainDate.from("2026-06-15");
console.log(release.dayOfWeek); // 1 (월요일)

// 날짜 계산 (불변)
const nextWeek = release.add({ weeks: 1 });
const diff = nextWeek.since(release);
console.log(diff.toString()); // "P7D"

// 타임존 변환
const meeting = Temporal.ZonedDateTime.from({
  year: 2026, month: 4, day: 10,
  hour: 10, minute: 0,
  timeZone: "America/New_York"
});
const seoulTime = meeting.withTimeZone("Asia/Seoul");
console.log(seoulTime.hour); // 23

// 기간 계산
const duration = Temporal.Duration.from({ hours: 2, minutes: 30 });
const total = duration.total({ unit: "minutes" });
console.log(total); // 150

ES2026 미리보기

ES2026에서는 다음 기능들이 준비 중이다.

  • Error.isError(): 값이 Error 객체인지 정확히 판별하는 정적 메서드
  • Map.prototype.upsert(): Map에서 값 추가 또는 수정을 한 번에 처리
  • Async Iterator Helpers: 비동기 이터레이터에도 map, filter 등 체이닝 지원

ES2025는 실무에서 바로 활용할 수 있는 기능이 많다. 특히 Set 연산과 Iterator Helpers는 코드 가독성과 성능을 동시에 개선하므로 적극적으로 도입하는 것을 권장한다.