The issue is that rowcol[i-1][j] is a string, and ! cannot be applied to a string. The same applies for each of your four lines.
Edit: If your goal is to check that the string is not null or empty, try instead:
var top = !(String.isNullOrEmpty(rowcol[i - 1][j])) ? rowcol[i - 1][j] : '';
and so on, or, if you know that the string will be null and not empty,
var top = (rowcol[i - 1][j]) != null) ? rowcol[i - 1][j] : '';