Ternary if statement
This provides a shorthand way to assign different values to a variable, depending on a condition.
var myVariable = document.getElementById("color").value myVariable == "red" ? 1 : 0;
This is identical to:
The following function performs the same test using the switch case statement. As you can see it is much more compact and consequently easier to read.
Nested if ... else statements
Very often several conditional tests may have to be performed, resulting in IF ... ELSE statements being nested one inside another. This can quickly get messy, and its very easy to miss-match a curly brace. Flow charts are a useful paper and pencil technique for sorting out more complex algorithms.
About the example templates
The examples therefore focus on standard features, ignoring any cross browser differences, except where specifically mentioned.
A preface to programming
Before looking at any specific programming language, there is some jargon we need deal with first. Today there are many different programming languages, here are just a few, So what's different about them?
SmartSim - Synchronous counters
In this example we'll use SmartSim to build a Synchronous counter using JK flip flops. No not a type of shoe, but a digital circuit that has memory, able store 1 bit of information. It works in much the same way as light switch in your home. When you turn a light ON, the switch remembers to keep the light on, until you decide to turn it OFF. I.e. it has two states, ON and OFF, or in binary logic terms TRUE and FALSE.