JS Built-ins
StringString.prototype.endsWithbeginner

String.prototype.endsWith() β€” no match

πŸ“– Usage Example
const str = 'Hello, World!'
str.endsWith('!')        // β†’ true
str.endsWith('World')    // β†’ false
str.endsWith('World', 12) // β†’ true

Use endsWith() to check if a string ends with a specific suffix, with an optional end position.

String.prototype.endsWith() β€” No Match

Challenge: Implement hasExtension(filename, ext) that checks if a filename ends with the given extension.

hasExtension('photo.jpg', '.jpg') // β†’ true
hasExtension('photo.png', '.jpg') // β†’ false
πŸ’‘ Hints (1)
  • β€’ Include the dot in the extension string for a precise match.