title: storing regexp in variable vs on the go value use
body: <p>Recently I have been so performance paranoid (I read those scary programming articles), that I started feeling that there is a bit performance difference between storing and accessing variable with static value and using that value on the go where needed;</p>
  
  <p>for e.g;</p>
  
  <pre><code>function check(name) {
      var match = name.match(/^Donald Middlename Trump$/i);
      if(!match) match = name.match(/^Hillary Mrs Clinton$/i);
      if(!match) match = name.match(/^Obama$/i);
      // e.t.c
  
      return match;
  }
  </code></pre>
  
  <p>My paranoia in the above function is that (correct me if am wrong, because <code>/^$/ == /^$/ // false</code>) I think that an instance of the RegExp object is created for the three regex, every time the check function is fired, ergo Javascript taking some time to create it every time. Though there is just one place each regex is used, but I feel the code will perform better by creating the regex once then referencing it from there on.</p>
  
  <p>for e.g.</p>
  
  <pre><code>var trump = /^Donald Middlename Trump$/i,
      hillary = /^Hillary Mrs Clinton$/i,
      obama = /^Obama$/i;
  
  function check(name) {
     var match = name.match(trump),
     if(!match) match = name.match(hillary);
     if(!match( match = name.match(obama);
  
     return match;
  }
  </code></pre>
  
  <p>Long question short, is there a performance difference or benefit between accessing a variable and recreating the object.</p>