Hello, JavaScript

The Course
•
4 min read

A program is a set of instructions. JavaScript executes the instructions you write; it does not guess what you intended. Start by pressing Run below. The area underneath is the console output: messages your program chooses to show.

console.log(...) prints a value. Text goes inside matching quotes. The parentheses hold what you want to print; the semicolon ends the instruction. We use semicolons consistently, even though JavaScript can insert some automatically. Lines beginning with // are comments for people and do not run.

Change the message, then run again. You have edited a real program. Capitalization matters: console.log and Console.log are different names. Try removing a closing quote, read the error, then restore it. An error message is a clue, not a grade.

How to use this course

Predict first, run second, and explain any surprise in a sentence. Write the exercise yourself before opening a hint. If you use AI, ask it for one hint or an explanation, verify the suggestion, then attempt a related problem without its answer in front of you.

No account or installation is needed. For Days 1–6, type input values directly into the code and read the output underneath it. These editors do calculations and show messages; they do not ask questions in pop-up boxes or change the webpage. Day 7 introduces a separate editor that can build webpages. JavaScript and Java are different languages.

Each example is a separate program. A variable you create in one editor is not available in another. Pressing Run starts that editor’s JavaScript program again from the top; use Reset to restore its supplied code. Try changing one small thing at a time. When an exercise asks you to “print,” it means use console.log to show output—not send anything to a printer.

Predict before running

How many lines appear, and in what order?

Predict, then run JavaScript
console.log("Hello, learner!");
console.log("One small step today.");
Check your prediction
Hello, learner!
One small step today.

Trace each statement in order. If your prediction differed, describe the first place your mental model and the result diverged before trying again.

Read code as a sequence

You can read a short program like a recipe: one instruction at a time. A comment can explain a step, but it cannot make a step happen. The text inside quotes is data, not a command. JavaScript will print the words console.log if you put them inside quotes.

Before running, point to each instruction and say exactly what it asks the computer to do. Then swap the first and last calls. Does moving the comment change the output?

Read code as a sequence JavaScript
console.log("First: open a notebook");
// This line is a note, not output.
console.log("console.log is the tool I am using");
console.log("Last: try one small change");
Check your prediction
First: open a notebook
console.log is the tool I am using
Last: try one small change

Only the three calls produce output. The quoted tool name is printed literally, rather than executed.

A first debugging routine

  1. Read the message; do not replace the whole program immediately.
  2. Check spelling and matching quotes, parentheses, and braces.
  3. Change one thing, rerun, and compare.

Try changing console to consol in the example. You should see a ReferenceError because the name is not defined. Restore it. Next, remove one closing quote: that is a SyntaxError because the program cannot be read. The exact wording varies by browser. Finally, put the wrong reminder inside valid quotes: this runs, but it is a logic mistake. Different failures need different investigations.

Save work you want to keep by copying it into a local text file. These editors are practice spaces; reloading can discard edits. You do not need to install tools today.

Your turn

Exercise

Hello, JavaScript: practise

Print a two-line study reminder: Open the course followed by Practise for 20 minutes.

Your working space JavaScript
// Write two console.log statements here.
Hint 1: the idea

Each call prints one message on a new line.

Hint 2: a first step

Start with the words inside quotes, then wrap them in console.log(…).

Show one solution
console.log("Open the course");
console.log("Practise for 20 minutes");
Open the course
Practise for 20 minutes

The calls run from top to bottom. Change the reminder into something useful to you. Can you write a third message without looking back?

What you should be able to explain

  • What is the difference between a comment, an instruction, and quoted text?
  • Can a program run successfully and still be wrong? Give an example.
  • Close the solution and write two messages about a different routine.

Was this article helpful?

Your response is saved on this device.