JS Built-ins
← String137 / 195
StringString.prototype.substringbeginner

String.prototype.substring() β€” start === end returns empty string

πŸ“– Usage Example
const str = 'Hello, World!'
str.substring(7, 12)   // β†’ 'World'
str.substring(5, 2)    // β†’ 'llo' (args swapped)
str.substring(7)       // β†’ 'World!'

Use substring() to extract characters between two indices, automatically swapping them if start is greater than end.

String.prototype.substring() β€” Same Indices

When start === end, .substring() returns an empty string.

Challenge: Implement emptySubstring(str, n) that calls substring(n, n).

emptySubstring('hello', 2) // β†’ ''
πŸ’‘ Hints (1)
  • β€’ When start and end are equal, there are no characters to extract.