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
Using indexOf or substring to test the end of a string
