CKTIS / JavaScript
String.prototype.substring — extracting part of a string
substring() returns the portion of a string between start and end, excluding end. It leaves the original unchanged, clamps indices to the string length, and swaps the boundaries when they are reversed.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
str.substring(start, end)String.prototype.substring returns a primitive string without changing the original. Indices are zero-based: start is inclusive and end is exclusive. Omitting end or passing undefined means the end of the string; omitting start means zero.
Arguments are converted to numbers, with fractional parts truncated toward zero. NaN and negative values become zero; values exceeding the string length are clamped to that length. The method then swaps the boundaries if the start exceeds the end. Equal boundaries produce "".
Unlike slice(), negative indices do not count backward from the end, and reversed boundaries do not force an empty result. Indices refer to UTF-16 code units, not complete visible characters; splitting a surrogate pair can return an incomplete character.
This is an ECMAScript standard-library method, not a Web API. The example demonstrates a range, swapped boundaries, a negative index, omitted end, and an empty result.
Examples
const text = "JavaScript";
console.log(text.substring(4, 10));
console.log(text.substring(10, 4));
console.log(text.substring(-3, 4));
console.log(text.substring(4));
console.log(JSON.stringify(text.substring(4, 4)));Result
Script Script Java Script ""
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.