What’s the Difference Between Slice, Substring, and Substr in Javascript?
If you’re trying to manipulate strings in Javascript, then you’ll most likely be using — or at the very least, considering — using the built in string manipulation functions.
Among these areslice()
, substring()
, and substr()
, and what can be confusing is the fact that all are somewhat similar in functionality. The natural question thus arises: what exactly is different about these? Are they pretty much interchangeable? At the end of the article, you will ideally know the answer.
A note about substr()
First of all, substr()
is considered deprecated and thus not suitable for use in new websites. That simplifies things, doesn’t it? However, you might be finding its usage in legacy code or something, so I think it’s still somewhat valuable to be aware of what it does.
I certainly would not dedicate too much headspace to it, though.