DEV Community

loading...

Discussion on: JS: Check if an email is valid

Collapse
lukeshiru profile image
▲ LUKE知る

Niche thing:

There is no point in structures like this:

function example (string) {
  if (string.test(/./gu)) {
    return true;
  }
  return false;
}
Enter fullscreen mode Exit fullscreen mode

String.prototype.test already returns a boolean, so is almost like saying:

"if x is true then return true, if not then return false"

Instead of just returning x. This is far better:

const example = string => string.test(/./gu);
Enter fullscreen mode Exit fullscreen mode