From the course: JavaScript: Best Practices for Data
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Remove unused variables - JavaScript Tutorial
From the course: JavaScript: Best Practices for Data
Remove unused variables
- [Instructor] I have code with some variables, a few functions, and some placeholder console.log statements for output. After some iteration my needs have changed, and I no longer need to run analysis using the cdRatio or efRatio. So I can take out the second and third functions, and I can take out the second and third console.log statements. At this point, I've cut a lot of my code. And especially if I was working in a big codebase, it can be easy to overlook orphaned variables, that is, variables that are declared but no longer used. ESLint can help me watch for this with the no-unused-vars rule. If I prune or restructure my code, such that a variable is no longer used anywhere in my code, ESLint will catch that for me. In my eslintrc file I'll add a new rule, no-unused-vars, and a simple string for the value of error. Now switching back to app.js, I have errors on line four and five that reference unused…
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
-
-
-
-
Prefer const, then let5m 7s
-
(Locked)
Use individual statements to create variables1m 41s
-
(Locked)
Create descriptive variable names3m
-
(Locked)
Standardize acronym case2m 22s
-
(Locked)
Remove unused variables1m 18s
-
(Locked)
Challenge: Declare variables45s
-
(Locked)
Solution: Declare variables5m 38s
-
-
-
-
-