Sikau

JavaScript · Day 5 · about 25 min

Comments and reading errors

Notes for humans, and staying calm with red text.

Errors are friends

Every programmer sees errors many times a day. An error isn't a sign you're bad at this — it's the computer telling you exactly where to look.

Today you'll learn to read errors calmly, and to leave notes in your code for yourself.

Comments

A comment is a note in your code that the computer ignores. It's written for humans — including future you.

// This line shows a greeting
console.log("Namaste");

console.log("Bye"); // a comment can go at the end too

/* A comment can also
   span several lines */

A handy trick: put // in front of a line to switch it off without deleting it. Programmers call this "commenting out". In the editor, Ctrl+/ (or Cmd+/ on a Mac) does it for you.

The rest of this lesson

  • Reading an error in three stepsexplain
  • The three errors you'll meet mostexplain
  • Name the errormatch
  • Debugging calmlyorder
  • Quick checkquiz
  • Fix three bugswrite code
  • Comment it outwrite code
  • Unit 1 complete!recap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript