Web hosting compare - CD-48 Part II . JavaScript Tutorial for an
CD-48 Part II . JavaScript Tutorial for an acceptable morsel. Your last stop in the store is the checkout aisle. Paper or plastic? the clerk asks. One more decision to make. What you choose impacts how you get the groceries from the car to the kitchen as well as your recycling habits. In your trip to the store, you go through the same kinds of decisions and repeti tions that your JavaScript programs also encounter. If you understand these frame works in real life, you can now look into the JavaScript equivalents and the syntax required to make them work. Control Structures In the vernacular of programming, the kinds of statements that make decisions and loop around to repeat themselves are called control structures. A control struc ture directs the execution flow through a sequence of script statements based on simple decisions and other factors. An important part of a control structure is the condition. Just as you may travel different routes to work depending on certain conditions (for example, nice weather, nighttime, attending a soccer game), so, too, does a program sometimes have to branch to an execution route if a certain condition exists. Each condition is an expression that evaluates to true or false one of those Boolean data types mentioned in Chapter 6. The kinds of expressions commonly used for conditions are expressions that include a comparison operator. You do the same in real life: If it is true that the outdoor temperature is less than freezing, then you put on a coat before going outside. In programming, however, the comparisons are strictly com parisons of number or string values. JavaScript provides several kinds of control structures for different programming situations. Three of the most common control structures you ll use are if construc tions, if…elseconstructions, and for loops. Chapter 39 covers in great detail other common control structures you should know, some of which were introduced only in Navigator 4 and Internet Explorer 4. For this tutorial, however, you need to learn about the three common ones just mentioned. if constructions The simplest program decision is to follow a special branch or path of the pro gram if a certain condition is true. Formal syntax for this construction follows. Items in italics get replaced in a real script with expressions and statements that fit the situation. if (condition) { statement[s] if true } Don t worry about the curly braces yet. Instead, get a feel for the basic structure. The keyword, if, is a must. In the parentheses goes an expression that evaluates to a Boolean value. This is the condition being tested as the program runs past this point. If the condition evaluates to true, then one or more statements inside the curly braces execute before continuing on with the next statement after the closing brace. If the condition evaluates to false, then the statements inside the curly brace are ignored and processing continues with the next statement after the clos ing brace.
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.