String.prototype.substring(indexStart, indexEnd?) returns a new string from indexStart up to (but not including) indexEnd. It never mutates the original string.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call string.substring. Start with this line.
JavaScript
str.substring(start, end?)
Call
What it does
str.substring(start, end?)
Primary signature.
string.substring(...)
Call with the arguments your case needs.
Built into JavaScript. Call substring(...) on a string (or String instance) — no import required.
Library declarations
JavaScript
str.substring(start, end?)
Parameters
Parameter
Description
indexStart
Required. Where the copy begins
indexEnd
Optional. Exclusive stop; omit → end of string
Return Value
Return Value
Description
*
New string (original unchanged)
JavaScript Examples
Example 1 — Extract with Start and End
Copy a piece of a string. The end index is exclusive.
Negatives differ.substring clamps to 0; slice counts from the end.
Rule of thumb. Prefer slice for new code unless you need the swap behavior.
Compatibility
Browser & Runtime Support
String.prototype.substring() is a long-standing part of JavaScript. It works in all browsers and Node.js versions you are likely to target.
✓ Baseline · Widely available
String.prototype.substring()
Supported everywhere JavaScript strings are — including legacy browsers. No polyfill needed for normal web or Node targets.
100%Universal support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
substring()Excellent
Bottom line: Safe in every environment that runs JavaScript. For negative-index extracts, prefer slice() for clearer intent.
Frequently Asked Questions
String.prototype.substring(indexStart, indexEnd?) returns a new string from indexStart up to (but not including) indexEnd. Omit indexEnd to go to the end of the string.
No. indexEnd is exclusive — the character at indexEnd is not included. For example "Mozilla".substring(0, 3) returns "Moz".
substring() swaps the two arguments. So "Mozilla".substring(3, 0) is the same as "Mozilla".substring(0, 3). slice() would return "" instead.
Unlike slice(), substring() treats negative values (and NaN) as 0. It does not count from the end of the string.
substring(start, end) uses two indexes. substr(start, length) uses a length (and is deprecated). Prefer substring or slice over substr.
Both are fine for non-negative indexes. Prefer slice() when you need negative indexes from the end. Prefer substring() only if you rely on its swap-when-start-greater-than-end behavior.