Why are .match() and .test() method sentax are opposite?

I’m going through the regex modules and they aren’t sinking in as easily as JavaScript for me and I think I just spotted why. There’s not a uniform way that regex methods are applied.

For .test() it’s regex.test(string). For .match() it’s string.match(regex). Is there a reason for this? I find this incredibly confusing and this seems to make internalizing regex harder than what I think it needs to be because there’s no consistency I can count on.

yes, it’s a bit weird.
match was created as a string method, test as a regex method.

1 Like

Gotcha. That makes a bit more sense to me. I’ll have to find some mnemonics on how to remember which sentax is which. #codeisweird

Its not really worth making an effort to memorize. Googling the MDN documentation is easy.

You make a great point.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.