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()
🌐
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.
🌐
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.
🌐
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.
🌐
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
The `trim` option in Mongoose schema definitions makes Mongoose automatically call `String.prototype.trim()` on string fields.
🌐
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.
Find elsewhere
🌐
Codecademy
codecademy.com › forum_questions › 5552c300e39efe6c520007af
What is the difference between slice and substring? | Codecademy
Is there a difference or are they the same, and why? 0 votes · Permalink · Hello Travis Block, There really is no difference. But if you think about it, substring is easier to use.
🌐
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.
🌐
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
🌐
Dynamics Community
community.dynamics.com › blogs › post
Difference between Slice, Substring & Split
slice(‘Shalinee’, 3) // Returns ... 3, 3) // Returns an empty string -”. 2. SUBSTRING: This returns a substring starting from the specified index and goes till the number of characters that you want in the substring....
🌐
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....
🌐
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.
🌐
MeasureThat
measurethat.net › Benchmarks › Show › 2335 › 1 › slice-vs-substr-vs-substring-with-no-end-index
Benchmark: slice vs substr vs substring (with no end index) - MeasureThat.net
slice vs substr vs substring with end · slice vs substr vs substring (with end index) @fran · slice vs substring (with no end index) slice vs substring (with end index) slice vs substr vs substrings · Comments · × · Do you really want to delete benchmark?
🌐
Bonsaiilabs
bonsaiilabs.com › substring-vs-slice
Difference between substring and slice JavaScript String - bonsaiilabs
This is because the start index is treated as zero and there is no end index, so all the characters till the end of the string are extracted and returned. Similar is the case with negative indexes. Any negative number that is passed as a start or end index will be treated as zero. Now with slice() method. The rule for passing, not a number is same as substring() method, but if the start or end index are negative, their corresponding values will be calculated as length of string plus start index and length of string plus end index depending upon which index was negative.
🌐
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 - The second parameter in substr() method is the length of the string to return from start index. Whereas the second parameter in substring() or slice() is, end index.
🌐
Ditectrev
blog.ditectrev.com › blog › software-development › web-development › frontend › javascript › slice-vs-substring-vs-substr-complete-javascript-string-methods-comparison
slice() vs substring() vs substr(): Complete JavaScript String Methods Comparison | 📝 Ditectrev Blog | #Build Your Digital Future.
January 12, 2026 - Important: substr() is deprecated and should not be used in new code. ... length (optional): The number of characters to extract. If omitted, extracts to the end of the string. Second Parameter is Length: Unlike slice() and substring(), the second parameter is the length, not the end index
🌐
Sonar Community
community.sonarsource.com › rules and languages
TypeScript: Prefer slice() over substring() - Rules and Languages - Sonar Community
February 12, 2025 - I would like to propose the following rule: Prefer slice() over substring() In ECMA String.prototype.sliceand String.prototype.substring are defined to perform the same operation on a string instance.