Skip to content

Commit d722c84

Browse files
delete: 1 edge case
1 parent f4374a3 commit d722c84

File tree

1 file changed

+0
-10
lines changed

1 file changed

+0
-10
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 & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -624,16 +624,6 @@ console.log(str.substring(4, 0)); // "Java"
624624
// Comparison with slice() (doesn't swap!):
625625
console.log(str.slice(4, 0)); // "" (empty string)
626626
// This is why substring() can hide bugs - it "fixes" what might be an error
627-
628-
// Example 2: Edge case - same values (no swap needed)
629-
console.log(str.substring(5, 5)); // "" (empty string)
630-
// Step-by-step:
631-
// 1. startIndex = 5, endIndex = 5
632-
// 2. Check: 5 > 5? NO → No swap
633-
// 3. Extract: indices from 5 to 5 (exclusive) → ""
634-
// Comparison with slice():
635-
console.log(str.slice(5, 5)); // "" (empty string)
636-
// slice() behaves the same - when start equals end, returns empty string
637627
```
638628

639629
#### Common `substring()` Pitfalls

0 commit comments

Comments
 (0)