title: what is the use of length optional parameter in endsWith() function?
body: <p>In the JavaScript method <code>endsWith</code> what is the use of optional length parameter?</p>
  
  <pre class="lang-js prettyprint-override"><code>str.endsWith(searchString[, length])
  </code></pre>
  
  <p>As per <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith" rel="nofollow noreferrer">documentation</a>:</p>
  
  <blockquote>
    <p>If provided, it is used as the length of str. Defaults to str.length.</p>
  </blockquote>
  
  <p>I still don't find any use of reason for this parameter. Is it used for increasing the efficiency of the search? What is the application in using this parameter?</p>