JavaScript Substring vs. Substr: Which One Should You Use? (String Methods Explained) (#76)
Need to pull specific text out of a string? JavaScript gives you two main ways: .substring() and .substr(). In this tutorial, we explain the mechanics of each and, more importantly, discuss why one of these is actually deprecated in modern web development. 👉 We’ll break down the "Start Index" and "End Index" logic versus the "Start Index" and "Length" logic so you never get confused again. What you will learn: ✔️ Mechanics: How indices work in a string (starting at 0). ✔️ Substring vs. Substr: Why the second argument changes everything. ✔️ Immutability: Understanding that strings are primitive and original values never change. ✔️ Modern Best Practices: Why you should stop using .substr() in 2026. ✔️ Edge Cases: What happens when you omit the second argument. 🕛 Timelines: 0:00 Introduction to String Methods 0:35 How .substring() works (Index to Index) 1:58 Extraction Logic: Inclusive vs. Exclusive 4:56 Introduction to the .substr() method 5:16 Why is .substr() Deprecated? 6:40 The Key Difference: Length vs. End Index 7:35 Immutability: Checking the Original String 8:27 Final Verdict: Use Substring for 2026 Projects 💡 The "2026 Best Practice" Tip As noted in the lecture, .substr() is deprecated. This doesn't mean it will stop working tomorrow, but it is no longer part of the core JavaScript language features and may be removed or unsupported by future tools/environments. 💡Peer Tip: Always use .substring() or the newer .slice() (which works on strings too!) to ensure your code remains future-proof.
Download
0 formatsNo download links available.