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.

🌐
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. The first character starts with index 0. ... Common Result Both give the same results in the given cases. ... If any argument is greater than the string's length, the string's length will be used in that case. JavaScript substring() different results of substring()
🌐
DEV Community
dev.to › hardiksharma › substring-vs-slice-vs-splice-4dj7
substring() vs slice() vs splice() - DEV Community
August 7, 2023 - This function is supposed to get a portion of a string from starting index to an end index. substring() takes two parameters: a start index and an end index.
🌐
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.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › substring-vs-slice
JavaScript `substring()` vs `slice()` - Mastering JS
With slice(), when you enter a negative number as an argument, the slice() interprets it as counting from the end of the string. With substring(), it will treat a negative value as zero.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › substring
Substring vs Substr vs Slice in JavaScript
Here's how you can check if the current URL contains a given string in JavaScript.
🌐
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.
🌐
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.
Find elsewhere
🌐
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.
🌐
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).
🌐
Jacklmoore
jacklmoore.com › notes › substring-substr-slice-javascript
JavaScript: Slice, Substring, or Substr?
"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. It supports extracting from the end of the string and I feel that returning an empty string when start index > stop follows the principle of least surprise better than substring's swapping of parameters.
🌐
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.
🌐
Bennadel
bennadel.com › blog › 2159-using-slice-substring-and-substr-in-javascript.htm
Using Slice(), Substring(), And Substr() In Javascript
April 21, 2020 - As you can see, the slice() and substring() methods are roughly the same; the only difference is that the slice() method can accept a negative index, relative to the end of the string.
🌐
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 you may be familiar with that support negative offsets, such as String#slice() 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 Wikipedia.)
🌐
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()
🌐
O'Reilly
oreilly.com › library › view › javascript-the-definitive › 9781449393854 › rn01re193.html
String.slice() - JavaScript: The Definitive Guide, 6th Edition [Book]
May 3, 2011 - The String methods slice(), ... argument values. slice() differs from substr() in that it specifies a substring with two character positions, while substr() uses one position and a length....
Author   David Flanagan
Published   2011
Pages   1093
🌐
MobileAppDaily
mobileappdaily.com › home › application development › javascript comparison of string.slice() vs string.substr() vs string.substring() in 2026
Comparing String.slice() Vs String.substr() Vs String.substring()
December 11, 2023 - What tells apart these JavaScript ... expecting two different outcomes. ... If we are using a 'substr' the second parameter is the number of the characters to include in the substring....
🌐
TestMu AI Community
community.testmuai.com › ask a question
What is the difference between String.slice and String.substring? - TestMu AI Community
May 13, 2025 - Does anyone know what the difference is between these two methods? String.prototype.slice String.prototype.substring
🌐
MSR
rajamsr.com › home › javascript substring vs slice: which one should you use?
JavaScript Substring vs Slice: Which One Should You Use? | MSR - Web Dev Simplified
March 13, 2024 - When should I use substring and when should I use slice in JavaScript? Use substring when you want to ensure that the provided indices are valid. Use slice when you want to handle negative indices or extract a substring up to the end of the string.
🌐
Reddit
reddit.com › r/learnjavascript › if you could only use string.slice or string.substring, which string method would you choose?
r/learnjavascript on Reddit: If you could only use string.slice or string.substring, which string method would you choose?
November 24, 2019 - Differences between the two: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring#Differences_between_substring_and_slice