Skip to content
Advertisement

Name check match pattern

I need help as to why code B is producing a different result

JavaScript

The code below (CODE A) produces the correct output (match)

JavaScript

However, the below (CODE B) produces a wrong output (no match)

JavaScript

Advertisement

Answer

To check a regex in an if-statement you’ll need to use =~ instead off ==;

JavaScript

Both will match as expected.

Try it online!

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement