JavaScript (ES2026) reference · String Methods

JavaScript String startsWith() Method

Return true if the string begins with the given text. Case-sensitive; an optional position starts the check later.

JavaScript (ES2026) Since ES2015

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

string.startsWith(searchString, position)

Parameters

ParameterDescription
searchString Text to look for.
position optional Index to check from. Default: 0

Return value

true or false.

Examples

Check a prefixTry it yourself
const url = "https://www.readycamel.com";
console.log(url.startsWith("https://"), url.startsWith("http://"));

Output

true false
From a positionTry it yourself
console.log("ReadyCamel".startsWith("Camel", 5));

Output

true

Version history

VersionChange
JavaScript ES2015Added

In other languages

Was this page helpful?