I was trying to print a grid of 4\*8, I have done everything as I should. the following code was run but it produced something totally different than I expected.

```js
var x = "";
for (var i = 1; i <= 8; i++) {
  x = " " + x;
  for (var j = 1; j <= 4; j++) {
    x = x + "#";
  }
  console.log(x);
}
```

but when I put the var x = ""; inside the first for loop, the outcome was a correct 4\*8 grid like the following:

```js
for (var i = 1; i <= 8; i++) {
  var x = "";
  x = " " + x;
  for (var j = 1; j <= 4; j++) {
    x = x + "#";
  }
  console.log(x);
}
```

I do not really understand why would that make a difference when it's in or out the loops, and if so, why does it need to be inside the first loop but not the seconds.