Arrow Functions Flashcards

1
Q

What are the rules of fat arrow?

A

1) Take out ‘function’ keyword and replace with arrow
2) One argument doesn’t need parentheses
3) Single JavaScript expression doesn’t need return or curly braces and can be one line
4) Two arguments and no argument require ()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When would you use arrow functions? In context of ‘this’. SUPER IMPORTANT

A

Compact syntax is nice, but…

The problem comes to head with the keyword ‘this’

1) in jQuery, we utilized the self = this call and cached this when we passed to an iterator function, which, when utilizing this, becomes lost in the ether and no longer has the desired context of this
2) in JS, we could also use .bind(this), which holds the this context

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why do fat arrow functions help with ‘this’?

A

They make use of lexical this

How well did you know this?
1
Not at all
2
3
4
5
Perfectly