Example 1 — Basic endsWith()
Ask whether a file name ends with a given extension.
const file = "report.pdf";
console.log(file.endsWith(".pdf"));
console.log(file.endsWith(".PDF"));
console.log(file.endsWith("port.pdf")); How It Works
- Exact suffix. The string ends with
".pdf"→true. - Case matters.
".PDF"is different →false. - Longer suffix.
"port.pdf"also matches the end →true.

