javascript - Is it good practice to use global variables in recursion -


I am helping someone in my school work - we are trying to write recursive functions (if this case Is - either in PHP or Javascript).

I understand the principles of recursion well, but I have not written any of them from the "academic" perspective.

Is it a good practice to use the global variable to store the result:

  var results = []; Var rec = function (a) {... if (match) results.push (someValue); }  

Should I use the refund to collect all those results together (which would be more difficult)?

There is probably a good practice to use as a small global variable, priority > 1

  var rec = function (a) {var someValue =   

[]; Function dorec () {// if the stuff happens (matches) results.push (someValue); }} Dorec (); }

1 states

All variables must be declared before using. Javascript is not required, but doing so makes the program easy to read and makes it easy to find undeclared variables which can be globally. The underlying global variable should never be used. Global variables should be used at least.


Comments