Example 1 — Basic startsWith()
Ask whether a string begins with a given prefix.
const str = "Saturday night plans";
console.log(str.startsWith("Sat")); // true
console.log(str.startsWith("Sat", 3)); // false
console.log(str.startsWith("night")); // false How It Works
- Default start is 0. Characters
0–2are"Sat"→true. - Position moves the start. From index
3the text is"urday…"→false. - Mid-string text is not a prefix.
"night"appears later, sostartsWithsays no. - Use includes for “anywhere”. Prefer
includes()when location does not matter.

