Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
JavaScript Substring Secrets: includes, startsWith, & endsWith Explained (#89)
Play lesson

🔥 JavaScript Mastery Course (2026) | Modern JavaScript ES6+ from Beginner to Advanced - JavaScript Substring Secrets: includes, startsWith, & endsWith Explained (#89)

5.0 (0)
6 learners

What you'll learn

This course includes

  • 28.5 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

Stop writing complex loops just to find a word in a sentence! JavaScript provides three highly readable methods to check for substrings: .includes(), .startsWith(), and .endsWith(). In this tutorial, we explain how these methods return true or false and how to handle case sensitivity.👉 We’ll build a real-world Email Validator and a Product Search Filter to show these methods in action. What you will learn: ✔️ The Big Three: How to check for content at the beginning, end, or anywhere in a string. ✔️ The Case Trap: Why "Hello" and "hello" aren't the same and how to fix it with .toLowerCase(). ✔️ Optional Positioning: Using the second argument to choose where the search starts. ✔️ Practical Case Study 1: Creating a function to validate emails without complex Regex. ✔️ Practical Case Study 2: Building a dynamic search filter for an array of product objects. ✔️ Logic Chaining: Using the ! (NOT) operator to create strict validation rules. 🕛 Timelines: 0:00 Introduction to Boolean String Methods 0:35 Master the .includes() Method 2:45 Case Sensitivity & Case-Insensitive Workarounds 4:15 The .startsWith() Method: Checking the Beginning 6:03 The .endsWith() Method: Checking the Tail 8:20 Practical Project 1: Building an Email Validator 10:00 Logical Refactoring: Cleaning up "if" statements 13:35 Practical Project 2: Filtering Products by Name 15:35 Combining .filter() with .includes() 19:25 Summary and Best Practices 💡 The "2026 Best Practice" Tip As noted in the lecture, these methods are built-in "sugar" for .indexOf(). While .indexOf() !== -1 still works, using .includes() makes your code much easier for other developers to read. In 2026, clean code is fast code—always prioritize readability when performance is comparable! 💡 Peer Tip: Remember that these methods work on Strings, but .includes() also works on Arrays! If you have a list of banned usernames, you can check bannedUsers.includes(userInput) just as easily as checking a single string. Expert Guide Question: If you were building a search bar that shows results as the user types, would you use .includes() or .startsWith() to provide the most helpful experience? Why?

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere