You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+13-2
Original file line number
Diff line number
Diff line change
@@ -8846,8 +8846,19 @@ The execution context is created when a function is called. The function's code
8846
8846
**[⬆ Back to Top](#table-of-contents)**
8847
8847
8848
8848
467. ### What is the difference between substring and substr methods?
8849
-
Both substring() and substr() are string methods, which are used to find substring of a given string. But there are some notable differences with their usage,
8850
-
8849
+
There are subtle differences between the substring() and substr() methods, so you should be careful not to get them confused.
8850
+
8851
+
- The two parameters of substr() are start and length, while for substring(), they are start and end.
8852
+
- substr()'s start index will wrap to the end of the string if it is negative, while substring() will clamp it to 0.
8853
+
- Negative lengths in substr() are treated as zero, while substring() will swap the two indexes if end is less than start.
8854
+
8855
+
Furthermore, substr() is considered a legacy feature in ECMAScript, so it is best to avoid using it if possible.
0 commit comments