Question · JavaScript and TypeScript course · Module 2: Functions, Arrays and Objects

replace() vs replaceAll() Method

What is the difference between replace() and replaceAll() in JavaScript?

Answer options

  • replace() replaces the first occurrence, replaceAll() replaces all
  • replace() works on arrays, replaceAll() on strings
  • There is no difference - both methods work identically
  • replace() modifies the original string, replaceAll() creates a copy
Show the answer

Correct answer:

  • replace() replaces the first occurrence, replaceAll() replaces all