From the course: JavaScript: Best Practices for Functions and Classes
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Use arrow syntax for anonymous functions - JavaScript Tutorial
From the course: JavaScript: Best Practices for Functions and Classes
Use arrow syntax for anonymous functions
- [Instructor] Named functions are a very common case when you need to create functions. Another is creating callback functions, like here in the start file for this video. This callback is created with a function keyword, which adds to the line length and can make the code harder to read. To avoid this, it's common to prefer arrow functions for inline callbacks. ESLint supports the prefer arrow callback rule, which lets you specify that ESLint should throw an error if your code doesn't use an arrow function for a callback. I'll add this to my eslintrc file. So, prefer-arrow-callback with error as the value, and I'll save that. And over in my JS file, I have an error and that is an unexpected function expression and it names the eslint rule that I just added. So, to fix this, I want to rewrite my callback function as an arrow function. And that's actually pretty straightforward to do. First, I'll take out that function…
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
-
(Locked)
Don't use the new keyword to construct functions2m 39s
-
(Locked)
Leave parameter values untouched3m 2s
-
(Locked)
Use arrow syntax for anonymous functions1m 36s
-
(Locked)
Rely on implicit return only when obvious3m 26s
-
(Locked)
Challenge: Create functions53s
-
(Locked)
Solution: Create functions5m 29s
-
-
-
-
-
-