DEV Community

Discussion on: How to Trim String in JavaScript

Collapse
 
lito profile image
Lito

But start is not from start of text, is from start of string and string starts always at position 0 from left. Is not related with string as localized language, is related with string as an element of javascript language.

Collapse
 
bytebodger profile image
Adam Nathaniel Davis • Edited

Yeah, I get that. And I'm not trying to imply that trimStart() is, in any way, "wrong". But we have two arbitrary names that could be used to describe the function. One of those names is universal - i.e., "left" is "left", everywhere. The other name is not universal. It forces you to think in terms of an "element of JavaScript", even though strings are very often associated with natural language and "start" and "end" mean different things, depending upon the natural language we're using. The standards group chose to recommend the meaning that is not universal. Hmm...

I'm not claiming it's any kinda huge tragedy. It would rarely cause anyone even the slightest of confusion. If you're a left-to-right native speaker like me (and most of us are), you'll probably never even think about the tiny little ambiguity. I just think that, if they'd thought that one through, they would have chosen the naming convention that is unambiguous.

There are only two hard things in computer science: cache invalidation and naming things. - Phil Karlton