Home / Javascript Tips Generated By ChatGPT / 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"