Help interpreting code

I’m following this React Tutorial and came accross this code. I’m just confused with the if statement.

function calculateWinner(squares) {
  const lines = [
    [0, 1, 2],
    [3, 4, 5],
    [6, 7, 8],
    [0, 3, 6],
    [1, 4, 7],
    [2, 5, 8],
    [0, 4, 8],
    [2, 4, 6],
  ];
  for (let i = 0; i < lines.length; i++) {
    const [a, b, c] = lines[i];
    if (squares[a] && squares[a] === squares[b] && squares[a] === squares[c]) {
      return squares[a];
    }
  }
  return null;
}

I get the destructuring part, but I can’t seem to make sense of that if statement. Isn’t that a Logical Operator AND (&&)? So like, if squares[a] is true return squares[a] strictly equal to squares[b]... :sweat_smile::rofl::scream:

My head is already spinning with the other React stuff and I love it. :smiley:

This if statement says return squares[a] only if square[s] has a “truthy” value AND squares[a] is strictly equal to squares[b] AND squares[a] is strictly equal to squares[c].

1 Like