"TypeError: undefined is not an object." Unexpected error

Viewed 17

I am following a tutorial on Udemy and this error occurred, I don't have idea why it happen and how to solve it. Would be very helpful, if you could explain.

Console screenshot

VSCode screenshot

Thank you, Mykyta.

Answer:

The problem was with for loop on line 7, when I removed "=" sign, error disappeared. Because I use ".length" property, it doesn't need an equal sign.

HTML code: ...

    <button class="show-modal">Show modal 1</button>
    <button class="show-modal">Show modal 2</button>
    <button class="show-modal">Show modal 3</button>

Declaration of a variable:

const btnOpenModal = document.querySelectorAll('.show-modal');

Here is a line of code that had a mistake:

for (let i = 0; i <= btnOpenModal.length; i++) <--- "="

Solution:

for (let i = 0; i < btnOpenModal.length; i++)

Sorry for taking your time, Mykyta.

0 Answers
Related