var x = “This is a long string”;
var slicedText = x.slice(–11);
and achieve the exact same output of ‘long string’
A method that is very similar to the slice method, but its usage differs slightly, is the subset method. The substr method operates in a very similar way: the first parameter is our starting position, just like with slice; however, the second parameter isn’t the ending position, but actually the length of the extracted segment. This allows us to specify how many characters we would like to ‘cut out’ of our string. Let’s see it in action: