Answers for "why to use arrow functions over normal function"

0

why to use arrow functions over normal function

// => why to choose arrow function over normal function 
1. short syntax, good as callback functions
 ([].map(() => {}) is better than [].map(function () {}))

2. when using class component, with arrow functions no need to bind this

// example: 

 -// this will be undefined
		button.addEventListener('click', () => {console.log(this); })
  // this will refer to dom button
		button.addEventListener('click', function () {console.log(this); })
Posted by: Guest on September-14-2021

Code answers related to "why to use arrow functions over normal function"

Code answers related to "Javascript"

Browse Popular Code Answers by Language