LearnFrenzy
Sign in Take a free test

String Methods · Find the Error · Question 3

Error: an unknown regex flag Answer, explanation & discussion

  • Find the error
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

JavaScript refuses to run the code below. Which statement correctly describes the problem?

main.js
const re = /hello/ix;
console.log(re.test("HELLO"));
  • A It prints true
  • B It prints false
  • C SyntaxError: x is not a valid JavaScript regex flag (valid flags are d, g, i, m, s, u, v, y) Correct
  • D The x flag is ignored
Correct Answer: Option C

Some other languages support an x (extended) flag; JavaScript does not, and an invalid flag in a literal is an early error.

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