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
1236

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
191

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.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › substring
String.prototype.substring() - JavaScript | MDN
The substring() method swaps its two arguments if indexStart is greater than indexEnd, meaning that a string is still returned. The slice() method returns an empty string if this is the case.
Discussions

JavaScript Substring Vs Substr Vs Slice Differences
You'd think this warning on MDN would be enough to cover the part about substr: Warning: Although String.prototype.substr(…) is not strictly deprecated (as in "removed from the Web standards"), it is defined in Annex B of the ECMA-262 standard, whose introduction states: … All of the language features and behaviours specified in this annex have one or more undesirable characteristics and in the absence of legacy usage would be removed from this specification. … … Programmers should not use or assume the existence of these features and behaviours when writing new ECMAScript code. … For that matter, you'd think that the general documentation on MDN would be enough to cover the rest of it. More on reddit.com
🌐 r/javascript
1
3
November 6, 2018
If you could only use string.slice or string.substring, which string method would you choose?
.slice() seems to have become more popular. Advantages: Accepts negative values as parameters. Same name as Array.protoype.slice() Differences between the two: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring#Differences_between_substring_and_slice More on reddit.com
🌐 r/learnjavascript
1
3
November 24, 2019
Why do we have a String.slice() method in JS ?
https://stackoverflow.com/a/2243835 This answer outlines the commonalities and differences between the two. More on reddit.com
🌐 r/learnjavascript
3
2
May 26, 2021
Exploring V8's strings: implementation and optimizations
Amazing article. The biggest, most practical, thing I learned was about Sliced Strings and how they hold a reference in memory to the full original string. That's definitely something I wouldn't expect and I can totally see how that would create a ton of extra memory usage for no good reason. Do you know which string methods create these string pointers? Is it anything that returns a substring? Eg: .match, .matchAll, .slice, .substr, .substring? More on reddit.com
🌐 r/javascript
20
40
November 14, 2023
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › substring
Substring vs Substr vs Slice in JavaScript - Mastering JS
June 20, 2019 - Like substring(), the slice() function takes the start and end indices as parameters, and is not considered a legacy function. Like substr(), the slice() function supports negative indices.
🌐
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()
🌐
W3Schools
w3schools.com › jsref › jsref_slice_string.asp
JavaScript String slice() Method
The substring() Method · string.slice(start, end) From position 3 to 8: let result = text.slice(3, 8); Try it Yourself » · Only the first character: let result = text.slice(0, 1); Try it Yourself » · Only the last character: let result = text.slice(-1); Try it Yourself » · The whole string: let result = text.slice(0); Try it Yourself » · JavaScript Strings ·
Find elsewhere
🌐
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.
🌐
Timotijhof
timotijhof.net › posts › 2020 › substr-substring-slice
Should I substr(), substring(), or slice()? – Timo Tijhof
September 26, 2020 - None of these seem unreasonable, in isolation. It’s nice that slice() allows negative offsets. It’s nice that substring() may limit the damage of accidentally negative offsets.
🌐
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).
🌐
TutorialsPoint
tutorialspoint.com › article › difference-between-string-slice-and-substring-methods
Difference Between String Slice and Substring Methods
March 15, 2026 - The slice() method extracts a section of a string and returns it as a new string without modifying the original string. ... The substring() method returns a portion of the string between the start and end indexes, or to the end of the string.
🌐
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 - And, in his examples, Haverbeke makes frequent use of the String method, slice(). When I think of slice(), I think of extracting portions of a Javascript array; I don't think I was even aware that the Javascript String prototype had a slice() method. To clear up my own confusion and misconceptions, I wanted to take a quick look at the various ways in which Javascript allows for partial string extraction. From what I can see, there are three primary methods for substring extraction:
🌐
DEV Community
dev.to › codepumps › what-is-the-difference-splice-slice-and-split-method-in-javascript-3mll
What is the difference splice, slice, and split method in Javascript ? - DEV Community
November 5, 2020 - Split() method is used for strings array, slice() method is used for both arrays and strings. Splice() method is used for only arrays. If you want to read more blog, you can check out my personal page.
🌐
Scribd
scribd.com › document › 500313673 › javascript-What-is-the-difference-between-String-slice-and-String-substring-Stack-Overflow
JavaScript: Slice vs Substring Explained | PDF | String (Computer Science) | Computer Science
String.slice() and String.substring() behave similarly, except that slice() treats negative indices differently than substring(). Specifically: 1. Both methods extract parts of a string and return them in a new string without modifying the original.
🌐
Reddit
reddit.com › r/javascript › javascript substring vs substr vs slice differences
r/javascript on Reddit: JavaScript Substring Vs Substr Vs Slice Differences
November 6, 2018 - Warning: Although String.prototype.substr(…) is not strictly deprecated (as in "removed from the Web standards"), it is defined in Annex B of the ECMA-262 standard, whose introduction states:
🌐
Codecademy
codecademy.com › forum_questions › 5552c300e39efe6c520007af
What is the difference between slice and substring? | Codecademy
I recently started learning about javascript and in a book I have been reading it uses .slice instead of .substring . Is there a difference or are the...
🌐
Squash
squash.io › javascript-substring-splice-and-slice-the-complete-guide
How to Use Javascript Substring, Splice, and Slice
May 1, 2023 - Learn how to use JavaScript's substring, splice, and slice methods. From extracting data from strings to modifying and paginating arrays.
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › window-sliding-technique
Sliding Window Technique - GeeksforGeeks
April 1, 2026 - Sliding Window Technique is a method used to solve problems that involve subarray or substring or window.
🌐
Ariya
ariya.io › 2014 › 02 › javascript-string-substring-substr-slice
JavaScript String: substring, substr, slice · ariya.io
February 27, 2014 - For all intents and purposes, slice has a behavior very close to substring (accepting start and end position). However, there is a minor difference. If the end value is smaller than the start, slice will not internally swap the values.
🌐
MobileAppDaily
mobileappdaily.com › home › application development › javascript comparison of string.slice() vs string.substr() vs string.substring() in 2026
JavaScript Comparison of String.slice() Vs String.substr() ...
May 4, 2026 - Understanding such core differences is especially useful for mobile app developers working with JavaScript-based frameworks, where efficient string handling directly impacts performance and user experience. ... If we are using a 'substr' the second parameter is the number of the characters to include in the substring. Like - ... But when we are using a 'substring', then the second parameter is the first index that is not to include. Like - ... The methods slice(), substring(), and substr() are the methods that extract parts of a string and then return the extracted parts in a new string.