slice() works like substring() with a few different behaviors.

Syntax: string.slice(start, stop);
Syntax: string.substring(start, stop);

What they have in common:

  1. If start equals stop: returns an empty string
  2. If stop is omitted: extracts characters to the end of the string
  3. If either argument is greater than the string's length, the string's length will be used instead.

Distinctions of substring():

  1. If start > stop, then substring will swap those 2 arguments.
  2. If either argument is negative or is NaN, it is treated as if it were 0.

Distinctions of slice():

  1. If start > stop, slice() will return the empty string. ("")
  2. If start is negative: sets char from the end of string, exactly like substr().
  3. If stop is negative: sets stop to: string.length – Math.abs(stop) (original value), except bounded at 0 (thus, Math.max(0, string.length + stop)) as covered in the ECMA specification.

Source: Rudimentary Art of Programming & Development: Javascript: substr() v.s. substring()

Answer from Daniel Vassallo on Stack Overflow
Top answer
1 of 9
1234

slice() works like substring() with a few different behaviors.

Syntax: string.slice(start, stop);
Syntax: string.substring(start, stop);

What they have in common:

  1. If start equals stop: returns an empty string
  2. If stop is omitted: extracts characters to the end of the string
  3. If either argument is greater than the string's length, the string's length will be used instead.

Distinctions of substring():

  1. If start > stop, then substring will swap those 2 arguments.
  2. If either argument is negative or is NaN, it is treated as if it were 0.

Distinctions of slice():

  1. If start > stop, slice() will return the empty string. ("")
  2. If start is negative: sets char from the end of string, exactly like substr().
  3. If stop is negative: sets stop to: string.length – Math.abs(stop) (original value), except bounded at 0 (thus, Math.max(0, string.length + stop)) as covered in the ECMA specification.

Source: Rudimentary Art of Programming & Development: Javascript: substr() v.s. substring()

2 of 9
190

TL;DR:

  • If you know the index (the position) on which you'll stop (but NOT include), use slice().
  • If you know the length of characters to be extracted, you could use substr(), but that is discouraged as it is deprecated.

Otherwise, read on for a full comparison

Syntax

  • string.slice(start,end)
  • string.substr(start,length)
  • string.substring(start,end)

Note #1: slice()==substring()

What it does?

  • slice() extracts parts of a string and returns the extracted parts in a new string.
  • substr() extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters.
  • substring() extracts parts of a string and returns the extracted parts in a new string.

Note #2: slice()==substring()

Changes the Original String?

  • slice() doesn't
  • substr() doesn't
  • substring() doesn't

Note #3: slice()==substr()==substring()

Using Negative Numbers as an Argument

  • slice() selects characters starting from the end of the string
  • substr() selects characters starting from the end of the string
  • substring() doesn't perform

Note #4: slice()==substr()

If the First Argument is Greater than the Second

  • slice() doesn't perform
  • substr() since the Second Argument is NOT a position, but length value, it will perform as usual, with no problems
  • substring() will swap the two arguments, and perform as usual

The First Argument

  • slice() required; starting Index
  • substr() required; starting Index
  • substring() required; starting Index

Note #5: slice()==substr()==substring()

The Second Argument

  • slice() optional; the position (up to, but not including) where to end the extraction
  • substr() optional; the number of characters to extract
  • substring() optional; the position (up to, but not including) where to end the extraction

Note #6: slice()==substring()

What if the Second Argument is Omitted?

  • slice() selects all characters from the start-position to the end of the string
  • substr() selects all characters from the start-position to the end of the string
  • substring() selects all characters from the start-position to the end of the string

Note #7: slice()==substr()==substring()

So, you can say that there's a difference between slice() and substr(), while substring() is basically a copy of slice().

If you want substr's functionality:

"foobarbaz".substr(index, length);

without using a deprecated feature, you can just do:

"foobarbaz".substring(index, length + index);

And get the exact same results bar all of the edge-cases, like negative index/length.

🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › substring-vs-slice
JavaScript `substring()` vs `slice()` - Mastering JS
A big difference with substring() is that if the 1st argument is greater than the 2nd argument, substring() will swap them. slice() returns an empty string if the 1st argument is greater than the 2nd argument.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › slice
String.prototype.slice() - JavaScript | MDN
If indexEnd is omitted or undefined, or if indexEnd >= str.length, slice() extracts to the end of the string. If indexEnd < 0, the index is counted from the end of the string. More formally, in this case, the substring ends at max(indexEnd + str.length, 0).
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › substring
Substring vs Substr vs Slice in JavaScript
Bite-sized full stack JavaScript tutorials for pragmatic developers that get things done
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › difference-between-string-slice-and-string-substring-in-javascript
Difference between String.slice and String.substring in JavaScript - GeeksforGeeks
July 11, 2025 - This function has the same syntax as slice() This method selects the part of a string and returns the selected part as a new string. Start and end parameters are used to specify the extracted part.
🌐
Jacklmoore
jacklmoore.com › notes › substring-substr-slice-javascript
JavaScript: Slice, Substring, or Substr?
"Good news, everyone!".substring(-4); // "Good news, everyone!" "Good news, everyone!".substr(-4); // "one!" modern browsers, including IE9 // "Good news, everyone!" IE8 and lower "Good news, everyone!".slice(-4); // "one!" Since all three methods have roughly equivalent performance, my preference is to use slice.
🌐
Medium
medium.com › swlh › whats-the-difference-between-slice-substring-and-substr-in-javascript-d410a4e0da70
What’s the Difference Between Slice, Substring, and Substr in Javascript? | by Tremaine Eto | The Startup | Medium
December 12, 2021 - 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.
🌐
Bonsaiilabs
bonsaiilabs.com › substring-vs-slice
Difference between substring and slice JavaScript String - bonsaiilabs
The end index is never included in the extracted string and it's optional. When not provided it extracts till the end of the string. This is a quick usage of substring() with just the start index 18 and it returns Apple,Peach. 00:48 Now there is another method to achieve the exact same result and that is the slice() method.
Find elsewhere
🌐
Medium
medium.com › @karthiknair20 › understanding-substring-and-slice-in-javascript-2e0eca8d84c8
Understanding substring() and slice() in Javascript | by Karthik Nair | Medium
April 16, 2025 - Use slice() when you want negative index support or more modern slicing behavior. Use substring() for non-negative indices and basic substring extraction. Pro Tip: In modern JavaScript, slice() is often preferred because of its flexibility — ...
🌐
Bennadel
bennadel.com › blog › 2159-using-slice-substring-and-substr-in-javascript.htm
Using Slice(), Substring(), And Substr() In Javascript
April 21, 2020 - For both the slice() and substring() methods, the second argument is exclusive; that is, the resultant substring will not contain the character at the final index. Let's take a look as these three approaches in action: <!DOCTYPE html> <html> <head> <title>Extracting Substrings In Javascript</title> <script type="text/javascript"> // For these demos, let's create a numbered string so that // we can easily see where the indexes come into play with // all of the substring methods.
🌐
Timotijhof
timotijhof.net › posts › 2020 › substr-substring-slice
Should I substr(), substring(), or slice()? – Timo Tijhof
September 26, 2020 - This in contrast to most methods ... or Array#slice(). The second parameter may not be negative. In fact, it isn’t an end index at all. Instead, it is the (maximum) number of characters to return. But, in Internet Explorer 8 (and earlier IE versions), the substr() method deviates from the ECMAScript spec. Its start parameter doesn’t support negative numbers. Instead, these are silently ignored and treated as zero. (I noticed this in 2014, shortly before we gracefully disabled JavaScript for IE 8 on ...
🌐
DEV Community
dev.to › hardiksharma › substring-vs-slice-vs-splice-4dj7
substring() vs slice() vs splice() - DEV Community
August 7, 2023 - These functions are used to get a part of an array or a string, with little differences and we will discuss these differences in this post. substring() is a function that can only be called on a string data type.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › substring
String.prototype.substring() - JavaScript | MDN
If either or both of the arguments are negative or NaN, the substring() method treats them as if they were 0. ... slice() also treats NaN arguments as 0, but when it is given negative values it counts backwards from the end of the string to find the indexes.
🌐
TutorialsPoint
tutorialspoint.com › difference-between-string-slice-and-substring-methods
Difference Between String Slice and Substring Methods
Slice method returns 'Morn' as output and substring method returns 'Good'. Substring method considers the end index as zero and since start index (5) is larger than the end index (0), it simply swaps their positions (0,5) and return the string.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-substring-examples-slice-substr-and-substring-methods-in-js
JavaScript Substring Examples - Slice, Substr, and Substring Methods in JS
March 22, 2020 - The slice method also expects the same two parameters: ... If we don’t set an ending index, then we get a substring starting from the given index number until the end of the original string:
🌐
To The New
tothenew.com › home › javascript : string.slice() vs string.substring() vs string.substr()
JavaScript : String.slice() vs String.substring() vs String.substr() | TO THE NEW Blog
August 28, 2016 - First character is at position 0. Use negative values to specify the position from the end of the string. Argument 2: end, Optional. The position (up to, but not including) where to end the extraction. If omitted, slice() selects all characters from the start-position to the end of the string.Use negative numbers to select from the end of the string.
🌐
Dillion's Blog
dillionmegida.com › p › string-substr-and-slice-method
substr and slice methods of strings in JavaScript - Dillion's Blog
substr and slice are string methods in JavaScript to cut out substrings from the full string. There's also substring but it's similar to slice.
🌐
Designcise
designcise.com › web › tutorial › what-is-the-difference-between-javascript-string-substring-and-string-slice-methods
JavaScript String.substring() vs. String.slice() – What's the Difference? - Designcise
September 2, 2022 - JavaScript · Frontend · Daniyal Hamid · 02 Sep, 2022 · 3 min read · Syntactically, both String.prototype.substring() and String.prototype.slice() are similar: str.substring(indexStart); str.substring(indexStart, indexEnd); str.slice(indexStart); str.slice(indexStart, indexEnd); And, they both behave in the same way when: indexStart equals indexEnd — they both return an empty string; indexEnd is omitted — they both extract characters to the end of the string; Either argument is greater than the string's length — the string's length will be used in both cases.
🌐
Arunkumar Blog
arungudelli.com › home › tutorial › javascript › javascript substring vs substr vs slice differences with examples
JavaScript Substring Vs Substr Vs Slice Differences With Examples
November 5, 2019 - And in the next version of JavaScript 1.2 introduced in Netscape 4.0, they wanted to support negative indexes to traverse the string from the reverse. And it is not a good idea to change the existing substring() function as it might break compatibility with existing scripts that expected negative indexes to treated as zero(0) So they created a new function to handle negative indexes and called it as slice()
Top answer
1 of 6
9

Even though it looks superficially like slice and substring do the same thing, the big difference is in how they handle negative arguments.

When JavaScript was first created in Netscape 2.0, there was just a substring method. If either of its arguments are negative, they are treated as 0.

When JavaScript 1.2 was introduced with Netscape 4.0, they wanted to add the behavior of allowing negative indexes to mean distances from the end of the string. They couldn't change substring to have this new behavior because it would break backward compatibility with scripts that expected negative indexes to be treated as 0, so they had to create a new function to support the added feature. This function was called slice, and was implemented on Array as well as String.

Another, smaller difference is that with substring the order of the arguments doesn't matter, so substring(1, 4) is the same as substring(4, 1). With slice, order does matter, so slice(4, 1) will just yield an empty string.

2 of 6
2

One item that makes them different is the second parameter that you have omitted

  • slice: the second parameter is the end index (exclusive) of the range to take.
  • substr: the second parameter is the length of the string to take from the index specified with the first parameter

Can you completely replicate the behavior of one method with the other on string instances? Yes. Why they chose to include both is probably lost to history. My guess though would be familiarity. I bet there are very few frameworks out there which have slice for strings but plenty that have substr.