Skip to content

Commit 1ca5f46

Browse files
delete: useless sections
1 parent 43ed56d commit 1ca5f46

File tree

1 file changed

+0
-52
lines changed

1 file changed

+0
-52
lines changed

data/blog/software-development/web-development/frontend/javascript/slice-vs-substring-vs-substr-complete-javascript-string-methods-comparison.mdx

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,18 +1174,6 @@ If you prefer video-based learning and want to learn JavaScript from industry ex
11741174

11751175
This video-based course provides insights into how JavaScript is used at scale in professional environments. It includes hands-on projects and assessments that help you build a portfolio of real JavaScript applications, perfect for visual learners who benefit from watching demonstrations and explanations.
11761176

1177-
### Why Continue Learning?
1178-
1179-
Understanding string methods like `slice()`, `substring()`, and `substr()` is important, but JavaScript is a vast language with many powerful features. These courses will help you:
1180-
1181-
- **Build Complete Applications**: Move beyond individual methods to full-stack development
1182-
- **Understand Modern JavaScript**: Learn ES6+, async/await, modules, and more
1183-
- **Work with Real Projects**: Apply your knowledge to build actual web applications
1184-
- **Follow Industry Standards**: Learn best practices used by professional developers
1185-
- **Prepare for Career Growth**: Gain skills that are in high demand in the job market
1186-
1187-
Whether you're a beginner looking to start your JavaScript journey or an experienced developer wanting to fill knowledge gaps, these courses provide structured, comprehensive learning paths that complement the detailed knowledge you've gained about string manipulation methods.
1188-
11891177
## Best Practices
11901178

11911179
### 1. Prefer slice() Over substring() and substr()
@@ -1309,43 +1297,3 @@ Understanding the differences between `String.prototype.slice()`, `String.protot
13091297
- All methods coerce non-number types to numbers
13101298
- `slice()` and `substring()` handle undefined differently (slice defaults better)
13111299
- NaN becomes 0 in all methods
1312-
1313-
### Practical Guidelines
1314-
1315-
- **Always use `slice()`** for new code and migrations
1316-
- **End index is exclusive**: `slice(0, 5)` includes indices 0,1,2,3,4 (not 5)
1317-
- **Negative indices are powerful**: `slice(-3)` gets last 3 characters elegantly
1318-
- **Consistency matters**: Use `slice()` consistently across your codebase
1319-
- **Unicode awareness**: All methods work with UTF-16 code units (not always code points)
1320-
- **Performance**: Differences are negligible; choose based on functionality
1321-
- **Migration**: Replace `substr()` and `substring()` with `slice()` when refactoring
1322-
1323-
### Quick Reference Table
1324-
1325-
| Scenario | `slice()` | `substring()` | `substr()` |
1326-
|----------|-----------|---------------|------------|
1327-
| Get last 3 chars | `str.slice(-3)`| `str.substring(str.length-3)`| `str.substr(-3)` ⚠️ |
1328-
| Extract middle | `str.slice(2, 5)`| `str.substring(2, 5)`| `str.substr(2, 3)` ⚠️ |
1329-
| Start > End | `""` (empty) ✅ | Swaps args ⚠️ | Works (length based) ⚠️ |
1330-
| Negative start | Works ✅ | Becomes 0 ❌ | Works ✅ |
1331-
| Negative end | Works ✅ | Becomes 0 ❌ | N/A (length param) |
1332-
1333-
**Legend**: ✅ Recommended | ⚠️ Works but not recommended | ❌ Problematic
1334-
1335-
### Memory Aid
1336-
1337-
Think of `slice()` like slicing bread:
1338-
- You specify where to start cutting and where to stop
1339-
- Negative numbers mean "from the end"
1340-
- It's precise and predictable
1341-
1342-
Think of `substring()` like a helpful but sometimes too-helpful assistant:
1343-
- It tries to fix your mistakes (swaps arguments)
1344-
- But this can hide real bugs
1345-
- It's less predictable
1346-
1347-
Think of `substr()` as outdated equipment:
1348-
- It uses a different measurement system (length vs index)
1349-
- Still works, but confusing
1350-
- Best to upgrade to modern tools (`slice()`)
1351-

0 commit comments

Comments
 (0)