Here I have hand-picked some of the most useful code snippets from 30 seconds of code. It's an awesome resource, go ahead and show it some love. In this article I tried to sort them based on their practical use, answering common questions you may fac...

Markdown supported Β· ββ΅ to post
The first example will not work as the el parameter will be an Array containing one element, a NodeList. The forEach will be called once, e will be a NodeList which does not have a syle property, so will result in a Uncaught TypeError: e.style is undefined error.
The following will work, which will, via the spread operator, convert the NodeList into an Array, thus giving access to the forEach method.
const hide = (...el) => el.forEach(e => (e.style.display = 'none'));
// Example
hide(...document.querySelectorAll('img')); // Hides all <img> elements on the page
Sahasra Reddy
Lucky the lover of Techy
youtube.com/watch