Skip to content

Files

Latest commit

 

History

History
21 lines (15 loc) · 479 Bytes

prefer-string-starts-ends-with.md

File metadata and controls

21 lines (15 loc) · 479 Bytes

Pattern: RegExp for string boundary check

Issue: -

Description

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.

Examples

Example of incorrect code:

const foo = "hello";
/^abc/.test(foo);

Example of correct code:

const foo = "hello";
foo.startsWith("abc");