Shane O'Sullivan's technical blog… really ties the room together

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 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

Extend Without Foreach


One Response to “JavaScript performance tips”

  1. 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 !!.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: