html5 javascript help

                for (var k = 0; k < original.length; k++)
                    original[k].normal && allowed.push(original[k]);


Could anyone explain what the programmer is doing here. I read it as cycling through an array and pushing those elements into a new array called allowed. but I have never come across && used in this way. I could only see the relevance of doing something this way, if it was looking for the opportunity to break it if there was not a original[k].normal.

I am not that familiar to html5 javascript, so if someone could give me a literal translation of what that line is trying to say.

All 2 Comments
original[k].normal && allowed.push(original[k]);

is just a shorter way of saying

if (original[k].normal != null) {



Thanks for the help, can you explain this line, it reads as though square2 will be a boolean to me.

 var square2 = !columnsLocked[squareI.col+axis.x] && board[squareI.col+axis.x] && board[squareI.col+axis.x][squareI.row+axis.y] && board[squareI.col+axis.x][squareI.row+axis.y];

Post a reply
Add Attachment
Submit Reply
Login to Reply