Imagine I have a function that is being called very often and needs to use a variable internally.
function busyFunction() {
var intermediateResult;
/* compute something */
return something;
}
As I understand, in this first example the browser will allocate memory for the variable and then schedule it for garbage collection at some point.
var intermediateResult;
function busyFunction() {
/* compute something */
return something;
}
I know the second example will pollute the scope outside of busyFunction. But since the the memory for the variable would not be garbage collected until the parent function is, would this be beneficial for performance? If I'm wrong here or if the effect is negligible, I'd rather use the first cleaner example.