title: trim in javascript ? what this code is doing?
body: <p>I was looking for a trim function in JavaScript which doesn't exist and some code on Googling suggests that use: </p>
  
  <pre><code>function trimStr(str) {
    return str.replace(/^\s+|\s+$/g, '');
  }
  </code></pre>
  
  <p>I want to know how <code>str.replace(/^\s+|\s+$/g, '')</code>
   works.  I understand that this is some form of regular expression but dont know what it is doing.</p>