Thursday, March 18, 2021

Regular Function vs Arrow Function

Regular Functions
  1. May or may not have a name, can be anonymous
  2. With name may be hoisted eg can declare function in a specific scope and call that function before its actually declare
  3. Able to have access the arguments

Arrow Functions
  1. always anonymous
  2. Cannot be hoisted
  3. Doesnt have own this so in arrow function, variables will be borrowed or taken from out of context.It may be useful in some node. It will refer to window like the global object hence you can’t perform some changes like the button or the dropdown menu
  4. Doesnt have access to arguments
  5. assign arrow function to variables and declaration of variables using const
  6. Usually used as callback functions which is a function that is passed as a argument in a call to another function cos callback function dont required to be named.
  7. Can be used as an immediately invoked arrow functions.

No comments:

Post a Comment