JS Built-ins
← String174 / 195
StringString.prototype.trimbeginner

String.prototype.trim() β€” no whitespace unchanged

πŸ“– Usage Example
'  hello  '.trim()      // β†’ 'hello'
'
 text 	'.trim()   // β†’ 'text'
'no spaces'.trim()   // β†’ 'no spaces'

Use trim() to remove all leading and trailing whitespace characters from a string.

String.prototype.trim() β€” No Whitespace

If the string has no leading or trailing whitespace, .trim() returns an equivalent string.

Challenge: Implement trimClean(str) and verify it works on clean strings.

trimClean('hello') // β†’ 'hello'
πŸ’‘ Hints (1)
  • β€’ `trim()` on a clean string is a no-op.