Por qué el código número uno es un código de escucha de eventos secundarios normal en js es más lento que el código número 2, el número dos es la delegación de eventos en js.
// #1 navLink.forEach(function (item) { item.addEventListener('click', function (e) { e.preventDefault(); const navId = item.getAttribute('href'); const navEl = document.querySelector(navId); navEl.scrollIntoView({ behavior: 'smooth' }); }); }); // #2 navLinks.addEventListener('click', function (e) { e.preventDefault(); // matching strategy if (e.target.classList.contains('nav__link')) { const navId = e.target.getAttribute('href'); const navEl = document.querySelector(navId); navEl.scrollIntoView({ behavior: 'smooth' }); } });