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

Remove unused variables - JavaScript Tutorial

From the course: JavaScript: Best Practices for Data

Start my 1-month free trial

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…

Contents