Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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); }) 
 
PREVIOUS NEXT
Tagged: #arrow #functions #normal #function
ADD COMMENT
Topic
Name
4+4 =