课程: JavaScript: Best Practices for Data

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Remove unused variables

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…

内容