Combining Case Clauses
You can combine the case clauses in a switch statement together so as to perform exactly the same processing for multiple values. Combining Case Clauses
You can combine the case clauses in a switch statement together so as to perform exactly the same processing for multiple values. Combining Case Clauses
When yo use a switch statement you need to specify the individual values that you are testing the field for. The default clause allows you to provide processing for all of those values not specifically catered for. The DEFAULT Clause
The if statement isn’t the only way that javaScript can make decisions. While an if statement can decide between true and false, the switch statement can test a single field for any number of different values and provide a different processing path for each. The SWITCH Statement
While a conventional if statement is relatively easy to read, it can be a bit long-winded in what you need to type in order to make decisions. Where the decision that is to be made is which of two or more possible values is to be assigned to a specific field, JavaScript provides an alternative [...]
Sometimes there are more than two possible outcomes that you want to process depending on which particular combination of conditions apply. By nesting if statements inside of other if statements you can tell JavaScript which outcome to apply when the appropriate combination of decisions are made. Nesting If Statements
Continuing on the series of tutorials on Making Decisions in JavaScript, this eighth tutorial looks at the logical operators AND, OR, and NOT and how they can be used to combine conditions together into a single test. Multiple Tests – And, Or, and Not
If statements in JavaScript evaluate the condition test as a boolean value. That means that it is either true or it is false. Of course of you don’t start with a boolean value or perform a comparison in order to create a boolean value then the condition will not be a boolean. When this happens [...]
JavaScript does comparisons using == and === and does assignments using =. When you are coding your if statements you might accidentally leave out an = converting your comparison into an assignment. You might then have a great deal of difficulty in locating why your code is not behaving as expected. In this sixth tutorial [...]
The one time that you don’t need to compare values to make a decision is when the value is what is known as a Boolean value. A Boolean value is either true or false (those are the only two values it can have) and we can therefore make decisions based on the value of a [...]
Most of the time in making decisions you need to compare something with something else. The tutorials on how JavaScript makes decisions therefore begins with information on how JavaScript handles comparing two values. Comparison Operators
Back in March 2007 a book publisher asked me to write a new book on JavaScript for them. I had the book all planned out and had written draft copies of several chapters before deciding that I just wasn’t going to have enough time to write the book in any acceptable amount of time. I [...]