Standard built-ins

String.prototype.startsWith()

Try the free JavaScript compiler

Tests a literal prefix at a specified normalized start; ordinary regex arguments are rejected.

Formal Syntax & Structure

javascript syntaxjavascript
text.startsWith(searchString, [position])

Parameters & Attributes

NameTypeDescription
searchStringStringLiteral sequence to locate.
positionNumberOptional search start position.

Return Value

Boolean

Whether the sequence starts there.

Working Example

Example Snippetjavascript
console.log("prepaid".startsWith("pre"));
JavaScript Reference