Question 1
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
console.log("a-b-c".replace("-", "+"), "a-b-c".replaceAll("-", "+"), "a-b-c".replace(/-/g, ""));
- A a+b+c a+b+c abc
- B a+b-c a+b+c abc Correct
- C a+b-c a+b-c a-b-c
- D a+b-c a+b+c ab-c
Correct Answer: Option B
A string pattern in replace changes the first match; replaceAll and a /g regex change all of them.
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!