Lesson 8 of 3324%

(Progress persistence is disabled until Phase 9)

JavaScript
Intermediate
20 min

Loops

Repeat code efficiently.

Learning Objectives

  • for and while loops

Loops

Welcome to this lesson on Loops. JavaScript is the programming language of the web, and loops is a fundamental piece of that ecosystem.

Explanation

When your browser loads a web page, the HTML creates the structure, the CSS creates the style, and JavaScript creates the interactivity. JavaScript can update both HTML and CSS in real-time.

Code Examples

Here is a simple snippet demonstrating this concept:

  console.log(i);
}
const arr = [1, 2, 3];
for (const num of arr) { console.log(num); }\n```

### Explanation of Code

In the example above, we define the logic required to implement the concept, and then execute it. The JavaScript engine parses this syntax and runs it.

<Callout type="warning">
**Common Mistake:** Watch out for syntax errors! Missing a bracket or a semicolon can sometimes break your entire script.
</Callout>

### Try It Yourself

Put this into practice! The BrowserCode runtime allows you to execute JavaScript securely in your browser.

<TryItButton />

### Key Takeaways
- JavaScript makes pages interactive.
- Always check your browser console for errors.

Lesson Progress

Practice This TopicTake QuizBuild a JavaScript Project

Ready to practise?

Apply what you learned with a hands-on challenge.

Practise This Topic