String.prototype.startsWith(searchString, position?) returns true if the string begins with the given prefix, otherwise false. Matching is case-sensitive (ES2015). Need a suffix check? Use endsWith(). Need “anywhere”? Prefer includes().
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call string.startsWith. Start with this line.
JavaScript
str.startsWith(searchString, position?)
Call
What it does
str.startsWith(searchString, position?)
Primary signature.
string.startsWith(...)
Call with the arguments your case needs.
Built into JavaScript. Call startsWith(...) on a string (or String instance) — no import required.
Library declarations
JavaScript
str.startsWith(searchString, position?)
Parameters
Parameter
Description
searchString
Required. Prefix to test (not a RegExp)
position
Optional. Index where the prefix must begin; default 0
Default start is 0. Characters 0–2 are "Sat" → true.
Position moves the start. From index 3 the text is "urday…" → false.
Mid-string text is not a prefix."night" appears later, so startsWith says no.
Use includes for “anywhere”. Prefer includes() when location does not matter.
Example 2 — Prefix from a Position
position sets where the prefix must sit — it does not search forward.
JavaScript
const str = "To be, or not to be, that is the question.";
console.log(str.startsWith("To be")); // true
console.log(str.startsWith("not to be")); // false
console.log(str.startsWith("not to be", 10)); // true
Case matters."File" is not the same as "file" → false.
Normalize first. Lower the string, then check the lower prefix → true.
Empty prefix.startsWith("") is always true, even on "".
Guard user input. Reject empty search strings if that “always true” result is unwanted.
Compatibility
Browser & Runtime Support
String.prototype.startsWith() is part of ES2015 (ES6). It works in all modern browsers and Node.js versions in common use today.
✓ Baseline · ES2015
String.prototype.startsWith()
Supported in Chrome 41+, Firefox 17+, Safari 9+, Edge 12+, and Node.js 4+. Not available in Internet Explorer without a polyfill.
98%Modern browser support
Google Chrome41+ · Desktop & Mobile
Full support
Mozilla Firefox17+ · Desktop & Mobile
Full support
Apple Safari9+ · macOS & iOS
Full support
Microsoft Edge12+ · Chromium & Legacy
Full support
Internet ExplorerNot supported · Polyfill needed
No support
Opera28+ · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.js4+ · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
startsWith()Excellent
Bottom line: Safe for modern web apps and current Node LTS. For IE11, feature-detect with typeof String.prototype.startsWith === "function" or fall back to str.slice(0, prefix.length) === prefix.
Frequently Asked Questions
startsWith(searchString, position?) returns true if the string begins with searchString (optionally checked from position), otherwise false. The search is case-sensitive.
Yes. "Hello".startsWith("hello") is false. Normalize both sides with toLowerCase() when you need a case-insensitive prefix check.
No. If searchString is a RegExp, startsWith() throws TypeError. Use RegExp.test() with a leading ^ for pattern prefixes.
true for any string. An empty search string is treated as a match at the start.
position is the index where the prefix must begin (default 0). For example "abcdef".startsWith("de", 3) is true because indexes 3–4 are "de".
startsWith() only checks the beginning (or from position as a new start). includes() looks for the substring anywhere in the remaining text.