Q:

How can I generate all possible states of an n-length binary string?

There are tons of questions like this here, I know, but I just read through 6 of them and they mostly pertain to generating all combinations of the character set with any length (a,b,c -> a, ab, abc ...) and / or only of the length of the string or list provided. 
What I'm trying to figure out how to do is represent all possible binary strings of a given length (encoded in base 2), and after reading all the questions I could find about this, I'm still having trouble figuring out how the function should be designed.
My goal is to have a function like:
var list = generateStates(3); // -> ['000', '111', '011', '001', '100', '110', '101', ... ]

The tricky part is I think I need to do this without recursion, because I want to do this with longer binary strings and the recursion can't be sustained that deep (without exceeding the maximum call stack). 

A:

function generateStates(n){
  var states = [];

  // Convert to decimal
  var maxDecimal = parseInt("1".repeat(n),2);

  // For every number between 0->decimal
  for(var i = 0; i <= maxDecimal; i++){
    // Convert to binary, pad with 0, and add to final results
    states.push(i.toString(2).padStart(n,'0'));
  }

  return states;
}

