JavaScript Perfromance Tip- Don’t Test Against obj.length. Test Against a Local Variable.
I saw it yesterday in some code I was debugging and I realized I’ve become hyper sensitive to this common pattern: var anchors = document.getElementsByTagName(‘a’); if (anchors.length > 0){ for (var i=0; i < anchors.length; i++) { addEvent( anchors[i], 'click', trackLinks ); }; }; Why am I sensitive to it? Well, what are some of […]