Content deleted Content added
→Operators: add content |
→Control structures: minor changes and additions |
||
Line 183:
==Control structures==
===If ... else===
if (
statements;
} else if (expr) {
statements;
} else {
statements;
}
*<code>else</code> statements must be cuddled (i.e. "<code>} else {</code>" , all on the same line), or else some browsers may not parse them correctly.
===[[Control_flow#Choice_based_on_specific_constant_values|Switch statement]]===
switch (
case
statements;
break;
case
statements;
break;
default
statements;
break;
}
*Add a break statement to the end of the last case as a precautionary measure, in case additional cases are added later.
*Strings can be used for the case values.
*Braces are required.
===[[For loop]]===
for (
statements;
}
===For ... in loop===
This loop goes through all enumerable properties of an object (or elements of an array).▼
▲ for (slot in object) {
▲ statements involving object[slot]
}
===[[While loop]]===
while (
statements;
}
===[[do while loop|Do ... while]]===
do {
statements;
} while (
==Functions==
|