Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 0.4 — Your First Program
JavaScript · Example 3 of 4

When two lines become one

Add a ; after const a = 1 (or at the start of the next line) and both items print.

A JavaScript program is a list of statements run from top to bottom; semicolons end statements (and are added automatically in most, but not all, places), comments are notes the engine ignores, and every name is case-sensitive.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write a program that stores the length (8) and width (5) of a room, works out the area, and logs Area: 40, with a comment for each step.

02

This code prints undefined. Fix it so it prints { ok: true }: ``js function check() { return { ok: true } } console.log(check())

03

Find and fix the two bugs: const UserName = "Ravi"; console.Log("Hi", userName);

Explain it without notes

01

What is the difference between a statement and an expression?

02

Explain Automatic Semicolon Insertion and give two cases where it surprises people.

03

What does case-sensitive mean in JavaScript, and what errors does a wrong capital cause?

04

When should you write a comment, and when shouldn't you?

When two lines become one

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

Before the problem
Uncaught TypeError: Cannot read properties of undefined (reading 'forEach')