Chapter 1 · Foundations

Reading errors

You are reading the whole lesson on one page. Back to one step at a time

Step 1 of 22 · Concept

Everyone gets errors

By the end of this lesson you can read what Node says when a program is wrong, and fix it.

Every programmer makes mistakes. Node's messages look strange at first, but they say what is wrong and where. You will:

  • read Node's messages, and fix one error at a time,
  • read the stack when a program stops in the middle,
  • find the mistakes that print no error at all.
console.log("Start");
console.log("Middle");
console.log("End";
console.log("Ready);
console.log("Set");
console.log("Go!";
function share(total, people) {
  return total.toFixed(2) / people;
}
console.log("Sharing...");
console.log(share(12, 4));
console.log(share(undefined, 4));
console.log("never");
function share(total, people) {
  return total.toFixed(2) / people;
}
console.log("Sharing...");
console.log(share(12, 4));
console.log(share(undefined, 5));
const apples = "5";
const pears = 3;
console.log("Total:", apples + pears);
console.log(apples, pears);
console.log(typeof apples, typeof pears);
const price = Number("2.50");
const count = Number("3");
const fee = Number("1,50");
const total = price * count + fee;
console.log("Price:", total);
const pizzas = 3;
const guests = 4;
const extra = "2"; // 2 extra slices, given as text
const slices = pizzas * 8 + extra;
console.log("Pizzas:", pizzas;
console.log("Slices:", slices);
console.log("Each:", slices / gusts);
function share(total, people) {
  if (people === 0) {
    console.log("people must be more than 0");
  }
  return total / people;
}
console.log("Each:", share(12, 4));
console.log("Each:", share(12, 0));
Terminal
Step 1 of 8A missing bracket

Keyboard shortcuts

The step

ContinueEnter
Previous / next stepAlt+[ · Alt+]
Move along the steps bar← → Home End, then Enter
From a quiz's title to its answers↓
Skip to the stepTab, then Enter (first on the page)
Course outlineAlt+O
These shortcuts?

The workspace

Run the stepCtrl+Enter (⌘↵ on a Mac)
Lesson → editor → consoleF6 (Shift+F6 back)
Output ↔ TerminalCtrl+`
Focus the editorCtrl+. (⌘. on a Mac)
Hide or show the lessonAlt+L
Restore, close a messageEsc (outside the editor and the terminal)

The editor

Leave the editorF6 (Shift+F6 back); or Ctrl+M (⌃⇧M on a Mac), then Tab moves the focus (not in the vim mode)
Open a file by nameCtrl+P (⌘P on a Mac)
All commandsCtrl+Shift+P (⌘⇧P on a Mac) or F1
Go to a lineCtrl+G (⌃G on a Mac)
Show or hide the filesCtrl+B (⌘B on a Mac)
Previous / next file tabCtrl+Shift+[ · Ctrl+Shift+] (⌘⇧[ · ⌘⇧] on a Mac)
The file tabs← → Home End on a tab; Delete closes it
Save the files nowCtrl+S (⌘S on a Mac)
Go to a symbol in the fileCtrl+Shift+O (⌘⇧O on a Mac)
Go to the definitionF12
Format the fileCtrl+Shift+F (⌘⇧F on a Mac), or Shift+Alt+F
Go back / forward after a jumpAlt+← · Alt+→ (⌃- · ⌃⇧- on a Mac)