JavaScript Substring vs. Substr: Which One Should You Use? (String Methods Explained) (#76)

Publicado el: 09 abril 2025
en el canal de: procademy
425
21

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.


En esta página del sitio puede ver el video en línea JavaScript Substring vs. Substr: Which One Should You Use? (String Methods Explained) (#76) de Duración hora minuto segunda en buena calidad , que subió el usuario procademy 09 abril 2025, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 425 veces y le gustó 21 a los espectadores. Disfruta viendo!