Chapter 2: Program Structure Flashcards
Two keywords to declare a binding (and their difference)
let
const
let creates a changeable binding, const an unchangeable one
if/else syntax
if( condition ){
true block
} else if ( condition ) {
false true block
} else {
false false block
}
while syntax
while ( condition ){
block
}
do syntax
do{
block
} while (condition)
Main difference between while and do
The code block within the do always executes at least once
for syntax
for (let counter = #; condition; update counter){
block
}
Command to stop a loop even when the while condition is still true
break
Command to skip the rest of the loop block and start the next iteration
continue
Four shortcuts to update number bindings
binding += #
binding *= #
binding++
binding–
switch syntax
switch(statement){
case value:
statements;
break;
case value:
statements;
break;
etc…
default:
statements;
break;
}
switch behavior with break
- evaluation starts at the case with a matching value (or the default)
- evaluation continues across all cases until a “break” is reached