Chapter 10 of 16All chapters
Chapter 10 of 16
Functions
Declarations, arrow functions and this.
Three ways to write one
A function declaration is hoisted and can be called before its line. A function expression is not. An arrow function is shorter and returns an expression without the return keyword when written on one line.
- Default parameters and rest parameters cover most argument juggling.
- Functions are values, so they can be passed around and returned.
What this means
In a normal function, this depends on how the function was called. An arrow function has no this of its own and borrows the surrounding one, which is why arrows are the safe choice inside callbacks.