Understanding the Difference Between substring and slice in Javascript


Both substring() and slice() can extract parts of strings, but slice() can accept negative indices.

Source Code

let text = "Hello, world!";
console.log(text.slice(-6, -1)); // "world"
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments