Like any kind of apps, there are difficult issues to solve when we write JavaScript apps.

In this article, we’ll look at some solutions to common JavaScript problems.

addEventListener vs onclick

addEventListener and onclick are equivalent.

However, we can use addEventListener to listen to events from more than one DOM element.

For instance, if we have:

element.addEventListener('click', () => { 
  //...
}, false);

Then we can listen to the click event of element .

We can also write:

element.onclick = () =>
  //...
}

which does the same thing.

We can use the event object to listen to multiple events.

For example, we can write:

element.addEventListener('click', (event) => { 
  //...
}, false);

Then we can use the event object to get the event data from elements that’s a child of element and check for actions.

#javascript #programming

JavaScript Tips — Listeners, Sorting, and Nested Objects
13.00 GEEK