Lesson 2 of 22 Β· 6 min Β· 2 hands-on steps

Printing Output & Writing Comments

Show anything on screen with console.log, and leave notes for humans with comments.

console.log shows things

console.log(...) prints whatever you put between the parentheses. Run this, then change it:

JavaScript Β· try it
Loading…

Notice the difference between the last two lines. With quotes, it's text and gets printed exactly. Without quotes, the computer calculates 2 + 3 first.

You can print several things at once by separating them with commas:

JavaScript Β· try it
Loading…

Comments are notes for humans

Anything after // on a line is a comment. The computer skips it completely.

JavaScript Β· try it
Loading…

Use comments to:

  • Explain why code does something unusual
  • Temporarily turn off a line while testing (called "commenting out")

Pro tip: good code explains what it does through clear names. Comments should explain why.

πŸ§ͺ Practice: 2 steps

0 / 2 done

Step 1 of 2 Β· Print three lines

Print these three lines, in this order:

Ready
Set
Code!
JavaScript
Loading editor…

Output appears here. Press Run or Ctrl/⌘ + Enter.

βœ… Check your understanding

  1. What happens to a line that starts with // ?

  2. What does console.log(2 + 3) print?

Create a free account to track your progress.