Pattern: RegExp for string boundary check
Issue: -
Using String#startsWith()
and String#endsWith()
is more readable and efficient than regular expressions with ^
or $
anchors when checking string boundaries. These methods don't require regex parsing overhead.
Example of incorrect code:
const foo = "hello";
/^abc/.test(foo);
Example of correct code:
const foo = "hello";
foo.startsWith("abc");