Skip to content Skip to sidebar Skip to footer

How To Interpret = And === In The Same Line?

I've come across this snippet of code render: function() { var boards = []; for (var ii = 0; ii < this.props.numBoards; ii++) { // We can compare to state here so

Solution 1:

The following code is executed in 2 steps

isSelected = ii === this.state.selectedIndex

1. ii === this.state.selectedIndex // comparator operator
2. isSelected = (result of step 1) // assignment operator

Solution 2:

For clarity that line should be written as:

isSelected = (ii === this.state.selectedIndex);

This is because == and === are for comparisons, the statement ii === this.state.selectedIndex will return either true or false and therefore isSelected will be true or false. Just like how if (ii === this.state.selectedIndex) will only execute its code block if the comparison statement is true.

Post a Comment for "How To Interpret = And === In The Same Line?"