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:
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:
Comments are notes for humans
Anything after // on a line is a comment. The computer skips it completely.
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 doneStep 1 of 2 Β· Print three lines
Print these three lines, in this order:
Ready
Set
Code!
Output appears here. Press Run or Ctrl/β + Enter.
Step 2 of 2 Β· Comment out a line
This program prints a line we don't want. Don't delete it. Turn it into a comment by putting // at the start, so the program only prints Keep me.
Output appears here. Press Run or Ctrl/β + Enter.
β Check your understanding
What happens to a line that starts with // ?
What does console.log(2 + 3) print?
Create a free account to track your progress.