Branching statements enable you to make choices. JavaScript has two branching statements: if and switch . The if statement is so important that we've already seen it at work both in this and the previous chapter; we'll take a look at it in depth here. This statement enables you to select which code to execute depending on whether a certain test condition (usually involving the comparison operators we've already seen, like this: votesForPizza > votesForHamburgers ). In fact, the if statement is so important in JavaScript that the other branching statement, the switch statement, is really just a modified if statement that you use when you want to handle multiple test conditions. We'll see both of them here, starting with the if statement. |