What is an algorithm?
A procedure for solving a problem in terms of the actions to be executed and the order in which they are executed.
What is pseudocode? Is it a programming language?
An informal language, similar to everyday English, that helps you develop algorithms. It is not an actual computer programming language.
Sequential execution vs. transfer of control
Sequential execution: statements execute in the order they appear. Transfer of control: changing the order in which statements execute.
Which three control statements are enough to write all scripts?
Sequence, selection and repetition.
Name JavaScript's three selection structures and their kind.
if — single-selection; if…else — double-selection; switch — multiple-selection.
Name JavaScript's four repetition statements.
while, do…while, for and for…in.
Which values are reserved words in JavaScript besides keywords?
null, true and false (plus words reserved for possible future use).
What does the JavaScript interpreter do with white space?
It ignores white-space characters (blanks, tabs and newlines used for indentation and vertical spacing).
Describe the conditional operator ?: .
Closely related to if…else; JavaScript's only ternary operator (three operands): a boolean expression, the value if true, and the value if false.
In nested if…else, which if does an else belong to?
The interpreter always associates an else with the previous if, unless told otherwise by the placement of braces ({}).
How many statements may an if body contain? What is a block?
Only one statement; to include several, enclose them in braces { } — a set of statements in braces is a block.
Fatal vs. nonfatal logic error
Both take effect at execution time. Fatal: the script fails and terminates prematurely. Nonfatal: the script continues but produces incorrect results.
What does a while statement do?
Repeats an action while some condition remains true; when the condition becomes false, repetition terminates.
Why is counter-controlled repetition called "definite repetition"?
Because the number of repetitions is known before the loop begins executing.
Total vs. counter
A total accumulates the sum of a series of values (normally initialized to zero). A counter is a variable used to count, typically in a repetition statement.
What is a sentinel value, and what else is it called?
A special value that indicates the end of data entry. Also called a signal value, a dummy value or a flag value.
Why is sentinel-controlled repetition called "indefinite repetition"?
Because the number of repetitions is not known in advance.
How should a sentinel value be chosen?
So that it cannot be confused with an acceptable input value.
Two ways control statements can be combined
Stacked on top of one another in sequence, or nested inside one another.
List the arithmetic assignment operators.
+=, -=, *=, /= and %= — they abbreviate common expressions (e.g., x += 2 means x = x + 2).
Prefix vs. postfix increment
Prefix (++a): increment by 1, then use the new value in the expression. Postfix (a++): use the current value in the expression, then increment by 1.
When do ++c and c++ have the same effect?
When the variable is incremented in a statement by itself. Inside a larger expression they have different effects.
Fig. 7.15: which operator groups associate right to left?
The unary ++ and --, the conditional ?: and the assignment operators (=, +=, -=, *=, /=, %=). The others listed associate left to right.