When you assign a DOM element an ID, that ID becomes part of the
window object. No joke, in the spec even ( emphasis mine ):
7.2.4 Named access on the Window object
The Window interface supports named properties. The supported property names at any moment consist of the following, in tree order, ignoring later duplicates:
the value of the id content attribute of any HTML element in the active document with a non-empty id content attribute.
On josephscott.org the sidebar section has an ID of “sidebar”, which is easily accessed in the Chrome Console:
document.getElementById( 'thingid' );, which is significantly faster.
I ran across a jsperf.com test of a for loop vs foreach and I was surprised at the difference when running the test in Chrome 38:
The for loop consistently came out over 40 times faster than the foreach.