You're confusing substring() and substr(): substring() expects two indices and not offset and length. In your case, the indices are 5 and 2, ie characters 2..4 will be returned as the higher index is excluded.

Answer from Christoph on Stack Overflow
🌐
Mimo
mimo.org › glossary › javascript › substring
JavaScript Substring Method: Learn String Extraction
The substring() method in JavaScript extracts a portion of a string and returns it as a new string without modifying the original string.
Discussions

How to check whether a string contains a substring in JavaScript? - Stack Overflow
Usually I would expect a String.contains() method, but there doesn't seem to be one. What is a reasonable way to check for this? More on stackoverflow.com
🌐 stackoverflow.com
7 Methods To Check If A String Contains A Substring In Javascript
check if a string contains a substring in javascript (in ES6): var I mean... I don't feel lodash or underscore are valid for this article. You're listing ways to check if a string has a substring, not external libraries that check that. Also, #7 has a typo: Syntax of includes method is include(string, substring) Should be includes. More on reddit.com
🌐 r/learnjavascript
1
0
February 18, 2019
Check if a String Contains a Substring in JavaScript
198k members in the learnjavascript community. This subreddit is for anyone who wants to learn JavaScript or help others do so. Questions and posts … More on reddit.com
🌐 r/learnjavascript
0
contains vs includes javascript?
There's no 'contains' method on strings in Javascript . More on reddit.com
🌐 r/learnjavascript
2
3
September 10, 2018
🌐
Refine
refine.dev › home › blog › tutorials › javascript substring method
JavaScript Substring Method | Refine
December 31, 2024 - JavaScript substring() is a String method that is typically used to extract and store part of a string.
🌐
Medium
medium.com › nerd-for-tech › basics-of-javascript-string-substring-method-1083c3d918e2
Basics of Javascript · String · substring() (method) | by Jakub Korch | Nerd For Tech | Medium
June 22, 2021 - If the second parameter is not provided, it extracts substring from starting position till the end. Second case shows a difference when the first parameter is greater than the second parameter. Obviously there is a difference, but unlike slice() that would return an empty string, substr() uses a second parameter to specify length of the substring, so the fact that the second parameter is less than the first parameter causes no issue and we just extract different parts of the string.
🌐
ReqBin
reqbin.com › code › javascript › i5foejaa › javascript-substring-example
How do I get a substring from a string in JavaScript?
January 29, 2023 - To get a substring from a string in JavaScript, you can use the built-in string.substring(start, end) method. The first parameter specifies the index of the first character from which to get the substring (in JavaScript, indexing starts from zero).
🌐
freeCodeCamp
freecodecamp.org › news › javascript-substring-examples-slice-substr-and-substring-methods-in-js
JavaScript Substring Examples - Slice, Substr, and Substring Methods in JS
March 22, 2020 - You can also watch the video version of the example usages here: Let’s start with the substring( ) method. This method basically gets a part of the original string and returns it as a new string.
Find elsewhere
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › String › substring
JavaScript String substring() - Extract Substring Range | Vultr Docs
September 27, 2024 - The substring() method in JavaScript is essential for extracting parts of a string based on specified index positions.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-string-substring-method
JavaScript String substring() Method - GeeksforGeeks
If only the starting index is provided, substring() will return the substring from that index to the end of the string. ... Like most string methods in JavaScript, substring() does not alter the original string.
Published   January 16, 2026
🌐
Great Learning
mygreatlearning.com › blog › it/software development › javascript substring() method: variants and uses
JavaScript substring() Method: Variants and Uses
March 31, 2025 - The substring() method in JavaScript extracts parts of a string between specified indices. This article explores its syntax, usage, key differences from similar methods like slice(), and practical applications such as extracting usernames or ...
🌐
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.
🌐
Tabnine
tabnine.com › home › how to use the substring method in js
How to Use the substring Method in JS - Tabnine
July 25, 2024 - In the example above, the substring() method is used to extract the portions of the string str between index 11 (which is included in the result) and index 18 (which is not included).
🌐
W3Schools
w3schools.com › jsref › jsref_substring.asp
JavaScript String substring() Method
The substring() method extracts characters, between two indices (positions), from a string, and returns the substring.
🌐
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.
🌐
Edureka
edureka.co › blog › javascript-substring
JavaScript Substring() | How is it different from substr() & slice()? | Edureka
January 9, 2025 - For example, “Welcome to Edureka” ... The substring() is an inbuilt function in JavaScript which returns a part of the given string from start index to end index....
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › substring
Substring vs Substr vs Slice in JavaScript
June 20, 2019 - Here's how you can check if the current URL contains a given string in JavaScript.
🌐
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 - 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()
🌐
JavaScript in Plain English
javascript.plainenglish.io › 10-ways-to-check-if-a-string-contains-substring-in-javascript-91639d81b7
10 Ways To Check If A String Contains Substring In JavaScript | by Sam C. Tomasi | JavaScript in Plain English
November 23, 2022 - This method allows you to check if a string contains a substring, and returns a boolean value. const string = "Hello World!"; console.log(string.includes("Hello")); // true console.log(string.includes("!")); // true console.log(string.includes("Hello World!")); // true console.log(string.includes("Hello World!!")); // false