String.prototype.endsWithintermediateconst str = 'Hello, World!'
str.endsWith('!') // β true
str.endsWith('World') // β false
str.endsWith('World', 12) // β trueUse endsWith() to check if a string ends with a specific suffix, with an optional end position.
The optional second argument endPosition treats the string as if it only goes up to that index.
'Hello World'.endsWith('Hello', 5) // β true
Challenge: Implement endsWithHello(str) that checks if the first 5 characters end with 'Hello'.