Conditions and Boolean Logic
- The if statement. An if statement runs its block only when its condition is true, and else catches every other case.
- Comparisons. Comparison operators like === and < produce a boolean, which is what an if statement actually reads.
- Combining conditions. The && operator needs both sides true, || needs either, and the not operator flips a condition to its opposite.
Loops and Iteration
- The for loop. A for loop repeats a block a controlled number of times: start, check, step, all declared up front.
- The while loop. A while loop repeats as long as its condition stays true: and loops forever if you never change it.
- for...of. The for...of loop walks the elements of an array directly, so you handle each item without counting indexes.
Control Flow and Program Decisions
- Early return. Handling the failing case first and leaving early keeps code flat: a guard clause instead of nested ifs.
- switch. A switch statement picks one branch from many by matching a value against cases, with break ending each branch.
- Tracing flow. To predict a program you trace it: follow the exact order lines run in, keeping each variable on paper.
Before and after this level
- Before: Level 1: JavaScript Foundations: Values, Variables and Operators, Expressions and Basic Types, Reading and Writing JavaScript.
- Next: Level 3: Functions & Scope: Functions, Parameters and Returns, Scope, Closures and Lexical Environment, Callbacks and Higher-Order Functions.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does JavaScript Level 2: Program Flow cover?
Conditions and Boolean Logic, Loops and Iteration, Control Flow and Program Decisions: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 1: JavaScript Foundations, which covers Values, Variables and Operators, Expressions and Basic Types, Reading and Writing JavaScript.