This question already has an answer here:
- What is the purpose of the var keyword and when to use it (or omit it)? 17 answers
I have found myself writing a lot of functions comprising of nested functions.
I like to use this pattern when doing so, as I find them easy to find again using the eclipse outline view
var outer_func = function(){
var inner_func1 = function(){
//code
}
var inner_func2 = function(){
//code
}
}
My question: Is there any scoping differences if I drop the var keyword from the nested/inner functions?
thanks for any advice.
If you leave off the inner var
keyword, then you will be creating global functions named inner_func1
and inner_func2
. Keep the var
.