diff --git a/javascript/.eslintrc b/javascript/.eslintrc index 3b76b5a..e470874 100644 --- a/javascript/.eslintrc +++ b/javascript/.eslintrc @@ -110,6 +110,10 @@ "semi": 2, // Disallow function definitions of the form 'function myFunc() {' - "func-style": [2, "expression"] + "func-style": [2, "expression"], + + // Disallow unused variables/expressions + "no-unused-vars": 2, + "no-unused-expressions": 2 } } diff --git a/javascript/README.md b/javascript/README.md index e521cc7..a7010ad 100644 --- a/javascript/README.md +++ b/javascript/README.md @@ -88,6 +88,21 @@ var length = items.length; var name = 'foo'; ```` +## Don't have unused variables/expressions +```javascript +// Bad: Many of these variables/expressions are useless +{} // object - not used +var newArray = []; // newArray - not used +['1', '2', '3', '4'].forEach(function(num, index) { // index - not used + return num++; +}); + +// Good: Delete things you no longer need +['1', '2', '3', '4'].forEach(function(num) { + return num++; +}); +``` + ##Use semi-colons There are many more ways that things can break *without* semi-colons than *with* semi-colons.