Flatiron SE Day 1 pt. 4
This one is all about arrow functions.
Brought in with the sweeping ES6 changes, arrow functions have become by new favorite thing.
Arrow functions allow you to significantly decrease the amount of space simple functions take. They have a few extra limitations beyond a standard function but can really simplify your code.
I have my coffee ready so let's get into today's lab!
Here are the parameters for passing the tests:
- has a function expression called divide
- divide divides 2000 by 100
- has an arrow function called square
- square arrow function takes one parameter and multiplies it times itself
- has an arrow function called add
- add arrow function takes two parameters and adds them together
Here is how I solved it:
//basic function expression for divide
const divide = function(){
return 2000 / 100
}
// arrow function
const square = num => num*num;
// arrow function with 2 arguments
const add = (num1, num2) => num1+num2;
I absolutely love the simplicity this offers.
This was pretty straightforward lab which was a lovely break from the last one that may have claimed a small piece of my soul.
Top comments (0)