From the course: JavaScript: Best Practices for Functions and Classes
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Solution: Create functions - JavaScript Tutorial
From the course: JavaScript: Best Practices for Functions and Classes
Solution: Create functions
(upbeat music) - [Teacher] The JavaScript code for this challenge contains a couple different functions. We've got the projection function here and then we've got an anonymous call back to array.reduce. So first off, I noticed that my projection function is using a function declaration and I want to use a function expression because it's a best practice. So first off, I'll throw in the ESLint rules that will flag that for me. And the first one's going to be func-style and it's going to be an array which is error and expression. And I'll also throw in no-new-func here. We don't have a new constructor going on here but I'm going to throw in the rule just because I can, because it's a good practice to have that getting flagged for me in case I ever do it on accident or in case I inherit some code that does it. So now everything is in red, everything is underlined and that's because I'm using this function declaration.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Use function expressions instead of declarations6m 20s
-
Don't use the new keyword to construct functions2m 39s
-
Leave parameter values untouched3m 2s
-
Use arrow syntax for anonymous functions1m 36s
-
Rely on implicit return only when obvious3m 26s
-
Challenge: Create functions53s
-
Solution: Create functions5m 29s
-
-
-
-
-
-