First, you should avoid functions inside functions in order to increase performance and, in addition, the DOM more slowly .
You can reorganize your code as follows:
function getLis(){ return document.getElementsByTagName('li'); } function test() { var ta = getLis(); }
Thus, javascript only stores these two functions in memory once, and you call them as many times as you want.
According to your question, it should be faster later, because it has fewer calls:
document.getElementsByTagName('li')
Regarding speed, my guess was right, I created a test case in jsperf:
Results:
document.getElementsByTagName ('Li')
2,141,067 ±2.07% fastest
document.getElementsByTagName ('body') [0] .getElementsByTagName ('Li')
704,856 ±4.40% 67% slower
And Screenshot:

source share