LearnFrenzy
Sign in Take a free test

String Methods · Predict the Output · Question 3

A replacer function Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.js
console.log("learn java script now".replace(/\b\w/g, (c) => c.toUpperCase()));
  • A Learn Java Script Now Correct
  • B LEARN JAVA SCRIPT NOW
  • C Learn java script now
  • D learn java script now
Correct Answer: Option A

\b\w matches the first character of each word, and the function upper-cases each match.

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