ECMAScript 2025(ES16)가 2025년 6월 정식 승인되면서 JavaScript에 다수의 실용적인 기능이 추가되었다. 이 글에서는 ES2025의 핵심 신기능들을 실제 코드 예제와 함께 상세히 다룬다.

1. Promise.try()

동기 함수와 비동기 함수를 동일한 방식으로 처리할 수 있는 Promise.try()가 추가되었다. 기존에는 동기 함수에서 예외가 발생하면 try-catch로 별도 처리해야 했지만, 이제 통일된 에러 핸들링이 가능하다.

// 기존 방식 - 동기 예외를 Promise로 감싸야 했음
function fetchData(id) {
    // JSON.parse가 동기적으로 throw하면 .catch()로 잡히지 않음
    return new Promise((resolve) => {
        const data = JSON.parse(localStorage.getItem(id));
        resolve(data);
    });
}

// ES2025 - Promise.try()로 깔끔하게 처리
function fetchData(id) {
    return Promise.try(() => {
        const data = JSON.parse(localStorage.getItem(id));
        return data;
    });
}

// 동기/비동기 함수 모두 동일하게 처리
Promise.try(() => syncFunction())
    .then(result => console.log(result))
    .catch(err => console.error("동기 에러도 여기서 처리:", err));

Promise.try(() => asyncFunction())
    .then(result => console.log(result))
    .catch(err => console.error("비동기 에러도 여기서 처리:", err));

2. Set 메서드 (집합 연산)

Set 객체에 합집합, 교집합, 차집합 등 수학적 집합 연산 메서드가 추가되었다. 기존에는 수동으로 반복문을 돌려야 했던 작업이 한 줄로 가능해졌다.

const frontend = new Set(["React", "Vue", "Angular", "Svelte"]);
const popular = new Set(["React", "Vue", "Node.js", "Express"]);

// union() - 합집합
const all = frontend.union(popular);
// Set {"React", "Vue", "Angular", "Svelte", "Node.js", "Express"}

// intersection() - 교집합
const both = frontend.intersection(popular);
// Set {"React", "Vue"}

// difference() - 차집합 (frontend에만 있는 것)
const onlyFrontend = frontend.difference(popular);
// Set {"Angular", "Svelte"}

// symmetricDifference() - 대칭 차집합 (한쪽에만 있는 것)
const exclusive = frontend.symmetricDifference(popular);
// Set {"Angular", "Svelte", "Node.js", "Express"}

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

// isSupersetOf() - 상위집합 확인
console.log(frontend.isSupersetOf(core)); // true

// isDisjointFrom() - 교집합 없음 확인
const backend = new Set(["Spring", "Django"]);
console.log(frontend.isDisjointFrom(backend)); // true

3. Iterator Helpers

이터레이터에 map, filter, take 등 배열과 유사한 헬퍼 메서드가 추가되어 지연 평가(lazy evaluation)가 가능해졌다.

// 기존 - 전체 배열을 메모리에 생성
const numbers = Array.from({length: 1000000}, (_, i) => i);
const result = numbers
    .filter(n => n % 2 === 0)
    .map(n => n * 2)
    .slice(0, 5);
// 100만 개를 전부 생성한 후 필터링

// ES2025 Iterator Helpers - 지연 평가
function* naturals() {
    let n = 0;
    while (true) yield n++;
}

const result = naturals()
    .filter(n => n % 2 === 0)   // 짝수만
    .map(n => n * 2)             // 2배
    .take(5)                     // 5개만
    .toArray();                  // 배열로 변환
// [0, 4, 8, 12, 16]
// 필요한 만큼만 계산 - 메모리 효율적

// drop() - 앞에서 N개 건너뛰기
const page2 = naturals()
    .filter(n => n > 0)
    .drop(10)      // 첫 10개 건너뛰기
    .take(10)      // 다음 10개 가져오기
    .toArray();
// [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]

// reduce() - 축약
const sum = naturals()
    .take(100)
    .reduce((acc, n) => acc + n, 0);
// 4950

// forEach() - 반복 실행
naturals()
    .take(3)
    .forEach(n => console.log(n));
// 0, 1, 2

4. RegExp Modifiers (패턴 내 플래그 변경)

정규식 내부에서 부분적으로 플래그를 변경할 수 있는 모디파이어가 추가되었다.

// (?ims-ims:pattern) 형식으로 플래그를 부분 적용
// i: 대소문자 무시, m: 멀티라인, s: dotAll

// 특정 부분만 대소문자 무시
const re = /(?i:hello) world/;
re.test("Hello world");  // true - hello 부분만 대소문자 무시
re.test("Hello World");  // false - world는 대소문자 구분

// 복합 활용
const re2 = /^START (?i:content) END$/;
re2.test("START content END");  // true
re2.test("START CONTENT END");  // true
re2.test("start content end");  // false - START/END는 대소문자 구분

5. Import Attributes (import assertions 대체)

// JSON 모듈 import
import config from "./config.json" with { type: "json" };
console.log(config.database.host);

// CSS 모듈 import
import styles from "./styles.css" with { type: "css" };
document.adoptedStyleSheets.push(styles);

// 동적 import에서도 사용 가능
const data = await import("./data.json", { with: { type: "json" } });

6. Duplicate Named Capture Groups

정규식에서 동일한 이름의 캡처 그룹을 여러 대안(alternative)에서 사용할 수 있게 되었다.

// 날짜 형식이 여러 가지일 때 동일한 그룹 이름 사용
const dateRe = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})|(?<month>\d{2})\/(?<day>\d{2})\/(?<year>\d{4})/;

const match1 = "2026-04-04".match(dateRe);
console.log(match1.groups.year);  // "2026"
console.log(match1.groups.month); // "04"

const match2 = "04/04/2026".match(dateRe);
console.log(match2.groups.year);  // "2026"
console.log(match2.groups.month); // "04"
// 형식이 달라도 같은 이름으로 접근 가능

7. Float16Array

AI/ML 분야에서 많이 사용되는 16비트 부동소수점 배열이 추가되었다.

// Float16Array - 메모리 효율적인 부동소수점 배열
const f16 = new Float16Array([1.5, 2.7, 3.14]);
console.log(f16.byteLength);  // 6 (각 2바이트)

// Float32Array 대비 메모리 50% 절약
const f32 = new Float32Array(1000000);  // 4MB
const f16arr = new Float16Array(1000000);  // 2MB

// Math.f16round() - Float16 정밀도로 반올림
console.log(Math.f16round(1.337)); // 1.3369140625

// DataView에서도 사용 가능
const buffer = new ArrayBuffer(4);
const view = new DataView(buffer);
view.setFloat16(0, 3.14);
console.log(view.getFloat16(0)); // 3.140625

브라우저 지원 현황

2026년 4월 기준 대부분의 ES2025 기능은 최신 Chrome, Firefox, Safari, Edge에서 지원된다. Node.js는 v22 이상에서 대부분 사용 가능하다. 프로덕션에서는 Babel이나 TypeScript 트랜스파일러를 통해 하위 호환성을 확보하는 것을 권장한다.