Bookcliff / learning

2 stars 0 forks source link

Learn about how arrow functions work #6

Closed Bookcliff closed 2 years ago

Bookcliff commented 2 years ago

Do #8 before this

Make sure to

Bookcliff commented 2 years ago

understand the different ways you can return values , return {} () ({})

Arrow functions do not explicitly require a return (it is implied), however, if there are multiple lines, you need the return. Arrow functions also treat curly braces after the arrow as the start of a block, so if you need to create/reference an object, you must put it within parentheses. Finally, functions do not require parameters and empty parentheses () can be used. However, if you add parameters, you can also assign default values to them for if a parameter is not passed in when the function is called.

understand how to write either a regular function or an arrow function

function counting(i) { return console.log(i); }

let countingNum = i => console.log(i);

RusseII commented 2 years ago

function counting(i) { console.log(i); }

let countingNum = i => console.log(i);

Those are not equal.

The following are equal. Do you know why?

function counting(i) {
console.log(i);
}
let countingNum = i => {console.log(i);}