String.replaceAll() Playground

The library notice board: replace or replaceAll, how many pieces does each swap? The swapped pieces are marked and checked against the JS engine. An…

Why it matters

Swapping every occurrence is everyday work (cleaning text, formatting, templates). Using .replace() wrong is a silent bug: some stay unchanged. Knowing replaceAll from a /g regex means correct code, safe from escaping traps.

The key idea

.replace(string) swaps only the first, replaceAll swaps them all

Common mistakes

Try it in this playground