Question 7
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
const userQuery = "price (incl"; // typed into a search box
const re = new RegExp(userQuery, "i");
console.log(re.test("Price (incl. GST)"));
- A It prints true
- B SyntaxError at run time: "(" opens a group that is never closed – escape user input before new RegExp Correct
- C It prints false
- D TypeError
Correct Answer: Option B
new RegExp parses its string at run time and throws "Invalid regular expression: Unterminated group". Escape metacharacters, or use includes on lower-cased text for plain searches.
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!