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
🌐
DEV Community
dev.to › hardiksharma › substring-vs-slice-vs-splice-4dj7
substring() vs slice() vs splice() - DEV Community
August 7, 2023 - It behaves similarly as substring and slice in this case and gives us back an array from start index to the end of the array but it also edits the original one.
🌐
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()
🌐
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 ...
Find elsewhere
🌐
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 ·
🌐
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.
🌐
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).
🌐
Bonsaiilabs
bonsaiilabs.com › substring-vs-slice
Difference between substring and slice JavaScript String - bonsaiilabs
It has the same syntax and accept the same two arguments, a start index and end index, and when we call slice() method on fruits string, it returns the exact same result. Now, what's the difference between the two? Let's look at few of them. With substring() method.
🌐
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.
🌐
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.
🌐
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...
🌐
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
The slice() method extracts parts of a string and returns the extracted parts in a new string. The substr() method extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters.
🌐
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:
🌐
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.
🌐
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 - substr and substring. ... The confusion mainly arises in these two JavaScript strings because they look very identical at the first glance, as both of these string methods also return a substring from a given string.
🌐
Jacklmoore
jacklmoore.com › notes › substring-substr-slice-javascript
JavaScript: Slice, Substring, or Substr?
June 25, 2011 - 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.
🌐
JavaScript in Plain English
javascript.plainenglish.io › when-do-you-use-splice-slice-substring-and-substr-f940cdde3db1
When Should You Use splice(), slice(), substring(), and ...
May 20, 2022 - In this section, we will discuss JavaScript built-in functions. Press enter or click to view image in full size · Photo by Oskar Yildiz on Unsplash · splice() slice() substring() and substr() When you want to cut or add a couple or a lot of characters in a string in JavaScript, there are a lot of options and this might confuse you.