← CodePrimer
JavaScript Beginner Dom

Arrow function event listener

Can I use an arrow function for events?

Modern listener syntax.

Sample
const countBtn = document.getElementById('countBtn');
countBtn.addEventListener('click', () => {
  console.log('Clicked with an arrow function');
});

Notes

Arrow functions do not bind their own this.

Keywords: arrow · addEventListener · click

Related

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share