Or is it substring? Might there be an off by one in there? Anyway, this kind of reflexion only proves my point. There's no reason to question what endsWith does, because it's obvious. It's the correct abstraction in many cases.
1. You need to know and understand obscure behavior of substr
2. This hides the programmer's true intent. What you want is to know if the string ends with 'st', not that "the 'st'.length last characters of the string is 'st'". Why make it harder on your fellow coworkers to understand what you mean ?
If you only do this once, sure, maybe importing a whole module is overkill. But as you write it over and over again, in separate projects, having the code safely tucked away in a reusable module brings complexity down.
I don't see why people insist on doing all the low level shit themselves, and then still complain about "scalability" and "fitness for programming on the enterprise level".
"test".substr("test".length - "st".length) === "st"
Or is it substring? Might there be an off by one in there? Anyway, this kind of reflexion only proves my point. There's no reason to question what endsWith does, because it's obvious. It's the correct abstraction in many cases.