Home > Article > Web Front-end > What is the difference between String.slice and String.substring in js
The difference between String.slice and String.substring in js is: 1. If [start>stop], then substring will exchange these two parameters; 2. If [start>stop], slice will return a null character string.
The difference between String.slice and String.substring in js is:
slice() is similar to substring( ) , but has some different behavior.
Syntax: string.slice(start, stop);
Syntax: string.substring(start, stop);
What do they have in common:
If start equals stop: Return an empty string
If stop is omitted: extract characters to the end of the string
If either parameter is greater than the length of the string, the length of the string will be used instead.
substring() Difference:
If start > stop, then substring will exchange these two parameters.
If either argument is negative or NaN, it is treated as 0.
slice() Difference:
Related free learning recommendations: JavaScript(Video)
The above is the detailed content of What is the difference between String.slice and String.substring in js. For more information, please follow other related articles on the PHP Chinese website!