str.startsWith(searchString)
determines whether str
begins with searchString
.
the 1st parameter, the string to search for
can be just a character
can be a string
can contain unicode characters
a regular expression throws a TypeError
the 2nd parameter, the position where to start searching from
e.g. find "str" at position 4
for undefined
is the same as 0
the parameter gets converted to an int
a value larger than the string`s length, returns false
this functionality can be used on non-strings too
e.g. a boolean
e.g. a number
also using the position works
Links
The official specification, actually quite good to read for this function.
The Mozilla Developer Network docs, contains good examples.
Required Knowledge
- basics (Arrow functions)
- `let` declaration (Block scope)
- `const` declaration (Block scope)
- as parameter (Rest operator)
- with arrays (Spread operator)
Related Katas
Template strings
String API
string.includes()
string.repeat(count)
string.startsWith()
string.endsWith()
String.raw
string.trimStart()
string.matchAll()
Difficulty Level
BEGINNER
First Published
26 August 2015
Stats
11 tests to solve