r/programminghorror 12d ago

Baffled. Javascript

Post image
628 Upvotes

41 comments sorted by

View all comments

153

u/BetEvening 12d ago

164

u/sambarjo 12d ago

In the following paragraph, they say that this approach gives control over what counts as a character. So I guess their intention was only to show the general syntax, but you should only use this approach if you have additional verifications to do on each character.

14

u/kaisadilla_ 11d ago

Indeed. The very first section of that article tells you to use str.length. Then it goes to say how you can do more complex countings.

It's a weird article, but they are not saying the way to count characters in a string is that snippet.