Cannot Read The Properties of undefined (reading ‘addEventListener’) at [duplicate]

I am trying to create a modal window. I have successfully created an open button however, I’m trying to create a close button by clicking the close modal button and the overlay, however, it is displaying that “cannot read the properties of undefined (reading ‘addEventListener’) at .. . )please help, much appreciated.

const overlay = document.querySelector(".overlay");
const modal = document.querySelector(".modal");
const showModal = document.querySelectorAll(".show-modal");
const btnCloseModal = document.querySelectorAll(".close-modal");


for (let i = 0; i <= showModal.length; i++)
showModal[i].addEventListener("click", function () {
    modal.classList.remove("hidden");
    overlay.classList.remove("hidden");
})
btnCloseModal.addEventListener("click", function(){
    modal.classList.add("hidden");
    overlay.classList.add("hidden");
})