30 min·beginner

Lesson 2

Console & statements

Build a practical mental model for console & statements and use it in working JavaScript.

By the end, you will be able to…

  • Explain console & statements in your own words
  • Use console & statements in a small program
  • Recognize and debug a common failure mode

Build the mental model

A program is a sequence of statements, and the console is your window into what actually happened versus what you expected. console.log, console.table, and console.error each format output differently to make different kinds of bugs easier to see.

Syntax and working example

Read the code from inputs to output. Predict what it prints, then run it and change one value.

Working example
Expected output: step 1 step 2 (a formatted table)

Why this matters

Professional developers narrate their program with console output long before they reach for a debugger, because it costs nothing and works everywhere.

Real-world example

Every production incident investigation starts with someone reading logs, which are just console statements captured at scale.

Common mistakes

  • Leaving stray console.log calls in shipped code
  • Logging a value without a label, making the output ambiguous
  • Only checking the last line of output instead of reading in order

Try it yourself

Challenge

Log three labeled values that show a variable changing over three steps.

Practice

Knowledge check

Why do professional developers use console.log while developing, not just when something breaks?

Summary

Statements run in order; the console is the cheapest, most reliable tool for observing that order and the values inside it.