LearnFrenzy
Sign in Take a free test

String Methods · String Methods MCQ · Question 2

replaceAll with a regex Answer, explanation & discussion

  • MCQ
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

What happens with "a.b.c".replaceAll(/\./, "-")?

  • A It returns "a-b-c"
  • B It returns "a-b.c"
  • C A TypeError: replaceAll requires a global (g) regex Correct
  • D It returns "a.b.c"
Correct Answer: Option C

Calling replaceAll with a non-global regex would be contradictory, so it throws. Write /\./g – or pass the plain string ".".

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links