Skip to content

Latest commit

 

History

History
21 lines (14 loc) · 656 Bytes

prefer-regexp-test.md

File metadata and controls

21 lines (14 loc) · 656 Bytes

Prefer RegExp#test() over String#match() and RegExp#exec()

When you want to know whether a pattern is found in a string, use RegExp#test() instead of String#match() and RegExp#exec().

This rule is fixable.

Fail

if (string.match(/unicorn/)) {}
if (/unicorn/.exec(string)) {}

Pass

if (/unicorn/.test(string)) {}