What’s the Difference Between Slice, Substring, and Substr in Javascript?

Tremaine Eto
The Startup
Published in
5 min readOct 26, 2020

--

Original photo by NESA by Makers on Unsplash; illustration by Tremaine Eto

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.

Input parameters: how to call them

slice()

--

--

Tremaine Eto
The Startup

Senior Software Engineer @ Iterable | Previously worked at DIRECTV, AT&T, and Tinder | UCLA Computer Science alumni | Follow me for software engineering tips!