Likely a simple question but I wasn't sure what to search for to find an answer.
In working my way through Eloquent Javascript, the following:
var size = 8;
var board;
for (var y = 0; y < size; y++) {
for (var x = 0; x < size; x++) {
if ((x + y) % 2 == 0)
board += " ";
else
board += "X";
}
board += "\n";
}
console.log(board);
Produces
undefined x x x x
x x x x
x x x x
x x x x
x x x x
x x x x
x x x x
x x x x
If I change the board variable to var board = ""; this doesn't happen.
I don't understand why, could someone enlighten me?
I'm running this in jfiddle.net with the https://getfirebug.com/firebug-lite-debug.js set up an external resource (to get the console).
var board;makesboardinitiallyundefinedundefined + " "yields"undefined "