JS Built-ins
← String135 / 195
StringString.prototype.startsWithbeginner

String.prototype.startsWith() β€” empty string always true

πŸ“– Usage Example
const str = 'Hello, World!'
str.startsWith('Hello')         // β†’ true
str.startsWith('World')         // β†’ false
str.startsWith('World', 7)      // β†’ true

Use startsWith() to check if a string begins with a specific prefix, with an optional start position.

String.prototype.startsWith() β€” Empty String

Every string starts with an empty string '', so .startsWith('') always returns true.

Challenge: Implement alwaysTrue(str) that checks if str starts with ''.

alwaysTrue('anything') // β†’ true
alwaysTrue('')         // β†’ true
πŸ’‘ Hints (1)
  • β€’ The empty string `""` is a prefix of every string.