The difference is in the second argument. The second argument to substring is the index to stop at (but not include), but the second argument to substr is the maximum length to return.

Links?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring

Answer from Delan Azabani on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › substring
String.prototype.substring() - JavaScript | MDN
The substring() method of String values returns the part of this string from the start index up to and excluding the end index, or to the end of the string if no end index is supplied.
Discussions

ecmascript 6 - Diferencias entre substr(), substring() y slice() Javascript - Stack Overflow en español
Fuente: Rudimentary Art of Programming & Development: Javascript: substr() v.s. substring() More on es.stackoverflow.com
🌐 es.stackoverflow.com
What is Difference between SUBSTR(), MID(), SUBSTRING() in SQL?
in SQL? they're all identical perhaps instead of "SQL" you meant "Microsoft SQL SERVER"??? More on reddit.com
🌐 r/SQL
4
1
January 8, 2020
When I can't remember the difference between slice, splice, substr and substring
Who needs consistency anyways. Somebody should tell the people that make JS standards that just because all other languages already use "start,length" they don't necessarily had to pick "start,end" More on reddit.com
🌐 r/ProgrammerHumor
7
339
February 19, 2022
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
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › difference-between-substr-and-substring-in-javascript
Difference between substr() and substring() in JavaScript - GeeksforGeeks
July 11, 2025 - In JavaScript Both of the functions are used to get the specified part of the string, But there is a slight difference between them. substr() and substring() are string methods used to extract parts of a string.
🌐
Jim Nielsen's Blog
blog.jim-nielsen.com › 2019 › difference-between-substr-and-substring-in-javascript
The Difference Between substring and substr in JavaScript - Jim Nielsen’s Blog
January 4, 2019 - The difference is in the second argument. The second argument to substring is the index to stop at (but not include), but the second argument to substr is the maximum length to return.
🌐
SkillForge
skillforge.com › substr-vs-substring-in-javascript
Substr vs Substring in JavaScript
Expert instructor-led training in Microsoft Office, Excel, Power BI, SharePoint, Azure, leadership, and more.
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › substr
String.prototype.substr() - JavaScript | MDN
The substr() method of String values returns a portion of this string, starting at the specified index and extending for a given number of characters afterwards.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › substring
Substring vs Substr vs Slice in JavaScript - Mastering JS
June 20, 2019 - There are 3 ways to get a substring of a string in JavaScript. In this tutorial, you will learn the difference between `String#substring()`, `String#substr()`, and `String#slice()`
🌐
LinkedIn
linkedin.com › pulse › javascript-tips-slice-substr-substring-gustavo-alves
Javascript Tips: slice, substr, substring
November 28, 2018 - The substr() method extracts parts of a string, beginning at the character at the specified position, with a specified number of characters.
Top answer
1 of 1
8

Resumiendo las diferencias:

String.prototype.substr() no está estrictamente obsoleto, pero no se recomienda su uso ya que puede dar resultados inconsistentes.

String.prototype.substring() devuelve un subconjunto de un objeto String.

String.prototype.slice() extrae una sección de una cadena y devuelve una cadena nueva.

slice() funciona como substring()con algunos comportamientos diferentes.

Syntaxis: string.slice(inicio, fin);
Syntaxis: string.substring(inicio, fin);

Lo que tienen en común:

  • Si inicio es igual fin: devuelve una cadena vacía.
  • Si fin se omite: extrae caracteres hasta el final de la cadena.
  • Si cualquiera de los argumentos es mayor que la longitud de la cadena, se utilizará en su lugar la longitud de la cadena.

Distinciones de :substring()

  • Si inicio > fin, entonces substring intercambiará esos 2 argumentos.

  • Si cualquiera de los argumentos es negativo o lo es NaN, se trata como si lo fuera 0.

Distinciones de :slice()

  • Si inicio > fin, slice() devolverá la cadena vacía. ("").

  • Si inicio es negativo: se establece el resultado desde el final de la cadena, exactamente como substr() en Firefox. Este comportamiento se observa tanto en Firefox como en IE.

  • Si inicio es negativo: se establece fin en: string.length – Math.abs(fin)(valor original), excepto limitado a 0 (por lo tanto Math.max(0, string.length + fin)) como se cubre en la especificación ECMA .

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


Luego para el problema que estas resolviendo (agrupar por comas de 3 en 3), creo que la función match es mas adecuada para el trabajo:

String.prototype.match() se usa para obtener todas las ocurrencias de una expresión regular dentro de una cadena.

En el siguiente código se ve como funciona:

function groupByCommas3(n) {
    let s = reverse(`${n}`).match(/.{1,3}/g);
    return reverse(s.join(','))
}
function reverse(cadena) {
    return cadena.split('').reverse().join('')
}

console.log(groupByCommas3(35235235));
console.log(groupByCommas3(1000000));
EjecutarEdit code snippet Hide Results Copy to answer Expand

esa es toda la información que te puedo dar sobre extracción de cadenas, saludos.

🌐
Log4JavaScript
log4javascript.org › home › js-framework › js substr: tips and examples
JS Substr: Tips and Examples - JavaScript For-Log
September 20, 2023 - In the world of JavaScript, manipulating strings is a fundamental task. Whether you’re working with user input, processing data, or creating dynamic content, string operations are essential. One such operation is extracting substrings from a given string, and JavaScript provides a built-in method for this called substring() or simply substr().
🌐
BitDegree
bitdegree.org › learn › javascript-substr
Discover JavaScript substr: substr JavaScript Explained
August 10, 2017 - The substr() method does not change the original string. Instead, it returns a new string, containing the trimmed part of the text. An empty string is returned if length is 0 or negative.
🌐
Altcademy
altcademy.com › blog › what-is-substring-in-javascript
What is Substring in JavaScript?
April 27, 2023 - If you are learning programming or just getting started with JavaScript, you might have come across the term "substring" and wondered what it means. In simple terms, a substring is a smaller part of a larger string.
🌐
Awsm
awsm.page › javascript › substring-vs-slice-in-javascript
Substring vs. slice in JavaScript
javascript • March 9, 2020 · Share on LinkedIn Share on X (formerly Twitter) Copy article link Share article · The syntax of substring is: str.substring(indexStart[, indexEnd]) Output will be of type string. While using substring you need to know the indexes both the start and end, so it'll work nice with hard coded strings or any fixed type of strings.
🌐
Untitled Publication
muteeb.hashnode.dev › understanding-the-differences-between-substring-substr-slice-and-splice
Understanding the Differences between substring, substr, slice, and splice
April 1, 2023 - substring() and substr() are used to extract a portion of a string and return a new string, while slice() and splice() are used to extract a portion of an array and return a new array or modify the original array, respectively.
🌐
Itsourcecode
itsourcecode.com › home › differences between javascript substring vs. substr
Differences Between JavaScript Substring vs. Substr - Itsourcecode.com
August 9, 2023 - Learn the differences between JavaScript substring vs. substr methods. Learn when and how to use each for optimal string manipulation.
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-substring-vs-substr
substring vs substr in JavaScript | DigitalOcean
November 6, 2017 - substr can be a negative integer, in which case the start of the returned string is counted from the end of the string that the method is used on:
🌐
RAPD
rapd.wordpress.com › 2007 › 07 › 12 › javascript-substr-vs-substring
Javascript: substr() v.s. substring() | RAPD
July 8, 2008 - If stop is omitted, slice extracted chars to the end of the string, exactly like substring().
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › split
String.prototype.split() - JavaScript | MDN
const splitByNumber = { [Symbol.split](str) { let num = 1; let pos = 0; const result = []; while (pos < str.length) { const matchPos = str.indexOf(num, pos); if (matchPos === -1) { result.push(str.substring(pos)); break; } result.push(str.substring(pos, matchPos)); pos = matchPos + String(num).length; num++; } return result; }, }; const myString = "a1bc2c5d3e4f"; console.log(myString.split(splitByNumber)); // [ "a", "bc", "c5d", "e", "f" ]
🌐
Edureka
edureka.co › blog › javascript-substring
JavaScript Substring() | How is it different from substr() & slice()? | Edureka
January 9, 2025 - The substring() is an inbuilt function in JavaScript which returns a part of the given string from start index to end index. The indexing starts from zero.