Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using var keyword in nested functions [duplicate]

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.

like image 745
Chin Avatar asked Dec 28 '25 22:12

Chin


1 Answers

If you leave off the inner var keyword, then you will be creating global functions named inner_func1 and inner_func2. Keep the var.

like image 117
Ned Batchelder Avatar answered Dec 30 '25 11:12

Ned Batchelder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!