Stage 1 · Lesson 3 of 10
Conditionals and loops
(if, else if and else) choose between paths, and repeat work. Use a classic for loop, for (let i = 0; i < n; i++), when you need the position number. Use for...of to walk the values of an array or string, and a while loop when you do not know the count in advance.
Do not use for...in on arrays. It walks the keys as strings and can include inherited ones, so keep it for objects. break leaves a loop and continue skips a pass.
Conditions use truthiness, which means some values count as false. 0, "", null, undefined and NaN are all falsy. So if (count) is false when count is 0, a classic bug.
Trace small loops on paper until errors (going one step too far or too short) stop happening.
A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking JavaScript Fundamentals
Design Gurus · Beginner · $50
The language itself, closures and async included, with runnable exercises per lesson
- GuideFreeJavaScript.info
Ilya Kantor
Free: Part 1 is the most complete modern JavaScript tutorial, with tasks per chapter