Skip to content

Commit 3192d65

Browse files
add: 1 more example in Side-by-Side
1 parent 62abb88 commit 3192d65

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,12 @@ console.log("\n=== Example 5: Start only (4) ===");
784784
console.log("slice(4):", str.slice(4)); // "Script"
785785
console.log("substring(4):", str.substring(4)); // "Script"
786786
console.log("substr(4):", str.substr(4)); // "Script"
787-
```
787+
788+
// Example 6: Positive start with negative end (substring swaps!)
789+
console.log("\n=== Example 6: Positive start, negative end (4, -3) ===");
790+
console.log("slice(4, -3):", str.slice(4, -3)); // "Scr" (from index 4 to -3, which is position 7)
791+
console.log("substring(4, -3):", str.substring(4, -3)); // "Java" (negative treated as 0, swaps to substring(0, 4))
792+
console.log("substr(4, -3):", str.substr(4, -3)); // "" (negative length treated as 0)
788793

789794
## Real-World Use Cases
790795

0 commit comments

Comments
 (0)