The 1, Slice (start,stop), and substring (start,stop) methods are used to extract characters from start to stop-1 in a string (since the string index starts at 0). Where start must be selected, stop is optional.
2, now mainly talk about the differences between the two
SUBSTRING (start,stop):
1. Returns an empty string when start equals stop.
2.stop Optional: If this argument is omitted, the returned substring continues until the end of the string.
3. If the start>stop,substring swaps two parameters, the end of the start-1 position starts at the beginning of the end parameter.
4. If any value in start or stop is greater than the length of the string, the value will be replaced by the length of the string. After the replacement to see if the condition 3 is met, then go on to the 3rd step.
5. If any value in start and stop is negative (<0) or Nan (not a number), then this value is treated as zero.
Slice (start,stop):
1. Returns an empty string when start equals stop, and substring is the same effect.
2.stop Optional: If this argument is omitted, the returned substring continues until the end of the string. The same effect as substring.
3. If the Start>stop,slice does not swap two parameter positions, it returns null "" directly.
4. If any value in start or stop is greater than the length of the string, the value will be replaced by the length of the string. The same effect as substring.
5. If start is a negative number (<0): Then the truncated string will start at the end of the stop with a string long datum, minus the start absolute value string.
Eg:var str = "abcdef"; var s1=str.slice ( -5,3); Console.info (S1)//BC ends at 6-5 to 3, 6 is string length =slice (1,3);
If End is negative: Then the stop is replaced by (length-1)-math.abs (stop);
Eg:var str= "abcdef"; var s1=str.slice (1,-2); Console.info (S1); BCD ends at 1 to 6-1 -2=3
And finally there's a subStr (start.length)
This is a good distinction, he returns the length character starting at start (including the character that the start refers to), not specifying length or length to return to the end string.
String Object slice and substring differences in JavaScript