JavaScript (ES2026) reference · String Methods

JavaScript String substring() Method

Return the part of a string between two indexes. Unlike slice(), negative values become 0 and swapped arguments are reordered.

JavaScript (ES2026) Since ES1

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

string.substring(start, end)

Parameters

ParameterDescription
start Start index.
end optional Index to stop before. Default: string.length

Return value

A new string.

Examples

Arguments are reorderedTry it yourself
const s = "JavaScript";
console.log(s.substring(0, 4), s.substring(4, 0));

Output

Java Java
Negative values: substring() vs slice()Try it yourself
const s = "JavaScript";
console.log(s.substring(-3), "|", s.slice(-3));

Output

JavaScript | ipt

Version history

VersionChange
JavaScript ES1Added

In other languages

Was this page helpful?