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

String.prototype.startsWith() β€” basic match

πŸ“– 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()

str.startsWith(searchString) returns true if str begins with searchString.

Challenge: Implement startsWithHello(str) that checks if a string starts with 'hello'.

startsWithHello('hello world') // β†’ true
startsWithHello('world hello') // β†’ false
πŸ’‘ Hints (1)
  • β€’ `str.startsWith(searchString)` returns `true` when `str` begins with `searchString`.