Probably this is dumb question, but I cant find the best answer for it.
Imagine if you have js file something like this:
//Home page rules
(function() {
//Header rules
(function() {
function myFunction1(){...}
}());
//Main section rules
(function() {
function myFunction2(){...}
}());
}());
And you need to use same variables in each function.One function is for animating elements on the page when page loads, and another function is for animating menu. I know that global variables should be avoided, I know that local variables has short lives - they are created when the function is invoked, and deleted when the function is finished (probably this is better performance).
QUESTION: What is the best practice and better performance: declare variables once at the top (inside home page rules) or duplicate (repeat your self) same variables in each of these functions?
Hope you get the point I am asking.