Start & End Checking in JavaScript

From the JavaScript String Methods cheat sheet · Searching & Testing · verified Jul 2026

Start & End Checking

Check if strings start or end with specific substrings

javascript
// Check string start
const str = 'JavaScript is awesome'
console.log(str.startsWith('Java'))     // true
console.log(str.startsWith('Script', 4)) // true (start from index 4)

// Check string end  
console.log(str.endsWith('awesome'))    // true
console.log(str.endsWith('is', 13))     // true (check up to position 13)
💡 More readable than indexOf() === 0 or slice() checks
⚡ Second parameter specifies search position
📌 Case-sensitive by default - lowercase for case-insensitive
✅ Perfect for validation and conditional logic
Back to the full JavaScript String Methods cheat sheet