August 2017
Beginner
298 pages
7h 4m
English
Arrow functions are a cleaner and shorter way to define functions in JavaScript and they simply inherit the this object of its parent instead of binding its own. We'll see more about the this binding soon. Let's just look into using the new syntax. Consider the following functions:
let a = function(x) {}let b = function(x, y) {}
The equivalent arrow functions can be written as:
let a = x => {}let b = (x,y) => {}
You can see that () are optional, when we have to pass the only single argument to the function.
Sometimes, we just return a value in a single line in our functions, such as:
let sum = function(x, y) { return x + y;}
If we want to directly return a value in our arrow function in a single line, we can directly ignore the ...
Read now
Unlock full access