Question discussion

What will be the output of the following JavaScript code?

359056Medium DSSSB TGT Computer Science 0 replies 0 views
0
What will be the output of the following JavaScript code?
const email = "example@domain";
const regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
console.log(regex.test(email));
  • AError: Invalid regex
  • Bundefined
  • CFALSE
  • DTRUE
Correct answer: C

Explanation

The email string has no dot after the domain, so the regex that needs ".xx" at the end does not match. test() returns false.

Discussion 0

Nobody has replied yet. Start the discussion!