title: How to handle unused variable in javascript function eslint errors?
body: <p>I have the following JavaScript functions which are linked to a HTML file, as they are called by a recordHistory() button in the HTML file. The JavaScript work well functionally, but in validation using eslint shows me these errors:
  'alerts' is defined but never used. (no-unused-vars) (this error for alert.js file)</p>
  <pre><code>// JavaScript Document
  function validateFirstName() { //test input for 2-15 allowed characters
      var fName = document.getElementById(&quot;firstName&quot;).value;
      var rel = /^[a-zA-Z\s\'\-]{2,15}$/;
      
      if (rel.test(fName)) { //if input is valid, update page to show successful entry}
          document.getElementById(&quot;firstNamePrompt&quot;).style.color = &quot;green&quot;;
          document.getElementById(&quot;firstNamePrompt&quot;).innerHTML = &quot;&lt;strong&gt;valid&lt;/strong&gt;&quot;
          return true;
  }
      else { //if input is invalid, update page to prompt for new input
              document.getElementById(&quot;firstNamePrompt&quot;).style.color = &quot;Red&quot;;
              document.getElementById(&quot;firstNamePrompt&quot;).innerHTML = &quot;&lt;strong&gt;Enter 2&amp;15&lt;/strong&gt;&quot;
              return false;
      }   
  }
  
  function validateLastName() { //test input for 2-25 allowed characters
      var lName = document.getElementById(&quot;lastName&quot;).value;
      var re2 = /^[a-zA-Z\s\'\-']{2,25}$/;
      
      if (re2.test(lName)) { //if input is valid, update page to show successful entry}
          document.getElementById(&quot;lastNamePrompt&quot;).style.color = &quot;green&quot;;
          document.getElementById(&quot;lastNamePrompt&quot;).innerHTML = &quot;&lt;strong&gt;valid&lt;/strong&gt;&quot;
          return true;
  }
      else { //if input is invalid, update page to prompt for new input
              document.getElementById(&quot;lastNamePrompt&quot;).style.color = &quot;Red&quot;;
              document.getElementById(&quot;lastNamePrompt&quot;).innerHTML = &quot;&lt;strong&gt;Enter 2&amp;25&lt;/strong&gt;&quot;
              return false;
      }   
  }
  
  function recordHistory(){//function to validate input text fields on client side, via record button
  var fName = document.getElementById(&quot;firstName&quot;).value;
  var lName = document.getElementById(&quot;lastName&quot;).value;
  if( fName ==='' || lName ===''){
  alert(&quot;Please fill all text fields...!!!!!!&quot;);
  return false;
  }else{
  return true;
  }   
  }
  </code></pre>
  <p>The error occurs at these lines:-</p>
  <ol>
  <li>function validateFirstName() { //test input for 2-15 allowed characters</li>
  <li>function validateLastName() { //test input for 2-25 allowed characters</li>
  <li>function recordHistory(){//function to validate input text fields on client side, via record button</li>
  </ol>
  <p>In the HTML file, the JavaScript functions are called by this function recordHistory():-</p>
  <pre><code>&lt;tr&gt;
          &lt;td class=&quot;Button&quot; id=&quot;Button&quot; colspan=&quot;3&quot;&gt;&lt;span class=&quot;buttonBG&quot; onclick=&quot;recordHistory();&quot;&gt;Record&lt;/span&gt;&lt;/td&gt;              
  &lt;/tr&gt;   
  </code></pre>
  <p>I referenced an example from this link [Disallow Unused Variables (no-unused-vars)][1] to help me solve the problem, but I couldn't get it to work</p>
  <p>[1]: <a href="https://eslint.org/docs/rules/no-unused-vars" rel="nofollow noreferrer">https://eslint.org/docs/rules/no-unused-vars</a>: -</p>
  <pre><code>// foo is considered used here
  myFunc(function foo() {
      // ...
  }.bind(this));
  
  (function(foo) {
      return foo;
  })();
  </code></pre>
  <p>This was what I tried for the FirstName JavaScript function, for example, but it didn't work: -</p>
  <pre><code>myFunc(function validateFirstName() { //test input for 2-15 allowed characters
      var fName = document.getElementById(&quot;firstName&quot;).value;
      var rel = /^[a-zA-Z\s\'\-]{2,15}$/;
  }.bind(this));
  (function(validateFirstName) {if (rel.test(fName)) { //if input is valid, update page to show successful entry}
          document.getElementById(&quot;firstNamePrompt&quot;).style.color = &quot;green&quot;;
          document.getElementById(&quot;firstNamePrompt&quot;).innerHTML = &quot;&lt;strong&gt;valid&lt;/strong&gt;&quot;
          return true;
  }
      else { //if input is invalid, update page to prompt for new input
              document.getElementById(&quot;firstNamePrompt&quot;).style.color = &quot;Red&quot;;
              document.getElementById(&quot;firstNamePrompt&quot;).innerHTML = &quot;&lt;strong&gt;Enter 2&amp;15&lt;/strong&gt;&quot;
              return false;
      }   
  })();
  </code></pre>