There are several ways of checking whether a string starts or ends with a certain string, such as string.indexOf('foo') === 0
or using regexes with /^foo/
or /foo$/
. ES2015 introduced simpler alternatives named String#startsWith
and String#endsWith
. This rule enforces the use of those whenever possible.
/^bar/.test(foo);
/bar$/.test(foo);
foo.startsWith('bar');
foo.endsWith('bar');