JavaScript's substring(): Quirky, Useful, Utterly Confusing
JavaScript's substring() looks innocent. It bites with swapped args and NaN forgiveness—tripping even vets.
⚡ Key Takeaways
- substring() auto-swaps args and forgives NaN/negatives—handy but hides bugs.
- Prefer slice() for negatives and predictability; substring for legacy tolerance.
- Always validate indices; JS strings butcher UTF-8 emojis without care.
Worth sharing?
Get the best Developer Tools stories of the week in your inbox — no noise, no spam.
Originally reported by dev.to