Sikau

JavaScript · Day 3 · about 20 min

The console

Where your code talks back to you.

Your code's voice

Most of what a program does happens invisibly. The console is how you ask it, "what are you doing right now?" Programmers use it every single day — even after 20 years of experience.

console.log, piece by piece

console.log("Good morning");
  • console — the place where messages appear.
  • .log — the action: write a line there.
  • ( ) — brackets hold what you're giving to the action.
  • ; — the end of the instruction.

console.log can show numbers too — and numbers don't need quotes:

console.log(2026);
console.log(7 + 3);
console.log("7 + 3");

You can show several things at once by separating them with commas. They appear on one line with spaces between.

console.log("Momo:", 12, "pieces");

The rest of this lesson

  • Predict the outputpredict
  • Common mistakeexplain
  • The console in every browserexplain
  • Text or maths?predict
  • Your turnwrite code
  • Mix text and numberswrite code
  • Challengechallenge
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript