I am pondering this:
function outer()
{
var myVar = 1;
function inner()
{
alert(myVar);
}
}
Now, as I understand it, this will result two lookups for the variable - one lookup to check the local variables in the inner function and one lookup for the outer function - at which point the variable is found.
The question is - will this be a particularly large drain on performance when compared to this:
function myFunc ()
{
var myVar = 1;
alert(myVar);
}
Which would only require the one lookup for the variable - it's then found as a local variable.
1 Answer 1
In older JS engines, scope lookups could cause some effects in performance.
However, even years back it was a very very minor difference - not really something you had to worry about.
Today's engines are most likely capable of optimizing lookups like this, and in general their performance is much much better. Unless you're writing something completely crazy or targeting a device with very poor performance, this is not something you need to worry about.
innerfunction. Also, no, it will not be a large drain on performance.