String.prototype.slicebeginnerconst str = 'Hello, World!'
str.slice(7, 12) // β 'World'
str.slice(-6, -1) // β 'World'
str.slice(7) // β 'World!'Use slice() to extract a portion of a string by start and end indices, supporting negative indices.
A negative start counts from the end of the string. str.slice(-3) gives the last 3 characters.
Challenge: Implement lastThree(str) that returns the last 3 characters.
lastThree('abcdef') // β 'def'
lastThree('hi') // β 'hi'