I am trying to improve my knowledge of javascript and, looking for some "best practices", someone pointed out to me that it is faster to cache the DOM document and then access it through this var instead of directly accessing the document object.
You can see the results here on the edit I made on jsperf: http://jsperf.com/jquery-document-cached-vs-uncached/3 (edit: the header contains "jsquery" because it was the original test, my editing contains vanilla javascript, the frames don't matter)
I'm really curious. Basically I am introducing a new variable into an equation, how can this make things faster, not slower?
As far as I know, "print a" should be better than "b = a; print b" (speech figure) What is different in this case?
source share