LearnFrenzy
Sign in Take a free test

String Methods · Predict the Output · Question 2

$& in a replacement Answer, explanation & discussion

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

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

main.js
console.log("price: 50 and 75".replace(/\d+/g, "₹$&"));
  • A price: ₹50 and ₹75 Correct
  • B price: ₹$& and ₹$&
  • C price: ₹50 and 75
  • D price: ₹ and ₹
Correct Answer: Option A

$& inserts the whole matched text, so each number is kept and prefixed with ₹.

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