Eloquent JavaScript chessboard
Fun question;


you should write a function that takes a parameter instead of just writing the code
A chessboard has lots of repetition, take a minute to ponder how String.repeat could make this code much simpler.
Your indentation is not perfect, consider using a site like http://jsbeautifier.org/
I am not a big fan of var within the loop, I would declare var up front.


This is a possible solution that provides the right size of the board:

function createChessboardString(size){

  const line = ' #'.repeat( size ),
        even = line.substring(0,size),
        odd = line.substring(1,size+1);
  let   out = '';

  while(size--){
    out = out + ((size % 2) ? odd: even ) + '\n';
  }

 return out;
}

console.log(createChessboardString(8));


You could consider for very large boards that the board in essence repeats 
odd + '\n' + even, so you could repeat that as well. The problem for me is that there are too many corner cases to consider. So personally I would go for the above for any board size &lt; 1000.