RegExp - JavaScript | MDN - Mozilla
If pattern is a regex, it would also interrogate pattern 's source and flags properties instead of coercing pattern to a string. For example, String.prototype.endsWith () would coerce all inputs to strings, but it would throw if the argument is a regex, because it's only designed to match strings, and using a regex is likely a developer mistake.