Replacing just the first delimiter leaves mixed formatting in an identifier. replaceAll makes the intended scope explicit.
Worked example
console.log("red green red".replaceAll("red", "blue"));Result
blue green blueImplementation notes
A literal search string treats punctuation as ordinary text. If the term becomes a regular expression, both escaping and the global flag become part of the contract.
Try it yourself
Include two adjacent delimiters and an input with no delimiter.
Open the JavaScript example →Editorial date October 10, 2026 · Published December 6, 2026