freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #58 of 61

ES2021 · replaceAll · numeric separators

LambdaVSThe Mutator
Lambda saysES2021 added String.replaceAll, numeric separators, Promise.any, and logical assignment.

str.replaceAll("a", "b") replaces every occurrence (no global-regex needed). Numeric separators (1_000_000) make big numbers readable. Promise.any resolves with the first success. Logical assignment operators (??=, ||=, &&=) tidy default-setting. Small but everyday quality-of-life wins.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleReplace all occurrences with replaceAll and write a big number with separators.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const out='a-a-a'.replaceAll('a','x'); const big=1_000_000;
document.getElementById('o').textContent=out+' · '+big.toLocaleString();</script></body></html>
▶ Open the interactive comic issue
‹ ES2020 · Optional Chaining · Nullish CoalescingES2022 · Top-Level Await · #Private Fields ›