javascript speed test

if you had to guess, which of the following two bits of javascript code would you say executes faster?

Exhibit A:

var keys = Object.keys(MyObj); //cloning the key array
var length = keys.length;
for (var i = 0; i < length; i++) {
  var val = MyObj[keys[i]];
};

Exhibit B:

for (var key in MyObj) {
 if (MyObj.hasOwnProperty(key)) { //hasOwnProperty is a native function
  var val = MyObj[key];
 }
}

Check your answer.


[More programming riddles]

 

 

 


this is what things looked like last year in september, with an up to date version of chrome:

Screen Shot 2013-09-17 at 7.04.32 PM

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s