JavaScript performance tips
Posted by Shane O'Sullivan on September 28, 2011
Every now and again a question comes up at work as to which of two or more approaches to the same problem in JavaScript performs better. I’ve started using the fantastic site jsperf.com to document these, so I’ll append to this post whenever I add a new test. I hope you find these useful, as they are answering questions that pertain to practical JavaScript usage.
Creating a regex inside and outside a loop
Declaring variables in a loop or outside it
Using hasOwnProperty or testing with undefined and void 0

Chris Barber said
Cool stuff. I added a test case to 3rd test (and forgot to enter my name, doh) that computed !!obj['foo'] and !!obj['notthere']. For me, it was the essentially the same speed as the void 0 method in Chrome, but was way slower in Firefox 7. Being the minimalist kinda guy I am, I prefer to save the 9 bytes and use !!.