JS Built-ins
← String183 / 195
StringString.prototype.trimStartbeginner

String.prototype.trimStart() β€” both ends β†’ only trailing preserved

πŸ“– Usage Example
'  hello  '.trimStart()   // β†’ 'hello  '
'   text'.trimStart()    // β†’ 'text'
'hi'.trimStart()          // β†’ 'hi'

Use trimStart() to remove only leading whitespace from the beginning of a string, leaving trailing whitespace intact.

String.prototype.trimStart() β€” Only Leading Removed

When both leading and trailing whitespace exist, trimStart() leaves the trailing intact.

Challenge: Implement keepTrailing(str) using trimStart.

keepTrailing('   hello   ') // β†’ 'hello   '
πŸ’‘ Hints (1)
  • β€’ `trimStart()` removes only the prefix whitespace, leaving the suffix intact.