arrow-functions
. Clone the empty repo to your dev environment.prework
folder in the root directory of the class repository. Then navigate into the arrow-functions folder.starter-code
into your newly-created repo. Make an initial commit with the unchanged starter code.app.js
file contains examples of function expressions, as you are accustomed to seeing. Work through steps 1-9, reading the notes and reviewing the refactored samples.index.html
file in the browser and verify the correct output in the developer console.this
, arguments
, or super
new.target
keywordcall
, apply
, and bind
methodsyield
within its body// Traditional Anonymous Function
(function (a) {
return a + 100;
});
// Arrow Function Break Down
// 1. Remove the word "function" and place arrow between the argument and opening body bracket
(a) => {
return a + 100;
};
// 2. Remove the body braces and word "return" — the return is implied.
(a) => a + 100;
// 3. Remove the argument parentheses
a => a + 100;
()
are required
// Traditional Anonymous Function
(function (a, b) {
return a + b + 100;
});
// Arrow Function
(a, b) => a + b + 100;
const a = 4;
const b = 2;
// Traditional Anonymous Function (no arguments)
(function() {
return a + b + 100;
});
// Arrow Function (no arguments)
() => a + b + 100;
{}
and return
are required
// Traditional Anonymous Function
(function (a, b) {
const chuck = 42;
return a + b + chuck;
});
// Arrow Function
(a, b) => {
const chuck = 42;
return a + b + chuck;
};
// Traditional Function
function bob(a) {
return a + 100;
}
// Arrow Function
const bob2 = (a) => a + 100;