Blog/Stop Treating console.log Like Training Wheels

Stop Treating console.log Like Training Wheels

console.log is not a beginner crutch. It is one of the first tools learners have for turning invisible program state into something they can inspect.

The problem is not that beginners log values. The problem is that they often log without a question.

That is the habit worth fixing.

Not "stop using console.log." That advice is too neat and not very useful. The better advice is: log with intent, predict before you run, and remove or refine logs when they stop teaching you anything.

Logging Is How Values Become Visible

JavaScript runs faster than beginners can think.

A variable changes. A function returns. A callback runs later. An array method calls your function once for every item. The browser fires an event. The learner sees the final result and has to reconstruct what happened.

console.log gives them a window.

function getDiscountedPrices(prices) {
  return prices.map((price) => price * 0.8);
}

console.log(getDiscountedPrices([10, 20, 30]));

That is not shameful. That is observation.

The next step is making the observation more precise:

function getDiscountedPrices(prices) {
  return prices.map((price) => {
    const discounted = price * 0.8;
    console.log({ price, discounted });
    return discounted;
  });
}

Now the learner can see each input and output pair. That is useful when a transformation is wrong.

The log has a job.

Bad Logging Has No Hypothesis

Bad logging looks like this:

console.log("here");
console.log(data);
console.log("test");
console.log(result);

We have all done some version of this. It is fine for ten seconds. Then it becomes fog with timestamps.

Good logging starts with a question:

Is this function receiving the value I think it is?
Is the array empty before or after filtering?
Does this event handler run once or twice?
Which branch of this conditional executes?

Then the log should answer that question directly:

console.log("before filter", users.length);

const activeUsers = users.filter((user) => user.active);

console.log("after filter", activeUsers.length);

That is better because the labels carry the hypothesis. The learner is not just dumping values. They are checking a story.

Debugging is story correction.

Predict Before Running

The most useful console.log habit happens before the log runs.

Ask the learner to write down or say what they expect:

const scores = [80, 55, 92];

const passing = scores.filter((score) => {
  score >= 70;
});

console.log(passing);

Before running it, they might predict:

[80, 92]

Then the console shows:

[]

That mismatch is the lesson.

The callback uses braces but never returns the comparison:

const passing = scores.filter((score) => {
  return score >= 70;
});

The goal is not merely to fix the code. The goal is to notice the gap between prediction and reality.

That gap is where learning happens.

This is why feedback loops matter so much. The faster learners can compare expected values to actual values, the faster they can update their mental model.

Log The Boundary, Not Every Brick

Beginners often log too much because they do not know where the important boundaries are.

A useful teaching move is to show them where to log:

  1. At the start of a function: what came in?
  2. Before a return: what is going out?
  3. Before and after a transformation: what changed?
  4. Inside a conditional: which branch ran?
  5. Inside an event handler: did the event fire, and what was the target?

For example:

function formatUsername(user) {
  console.log("formatUsername input", user);

  const username = user.name.trim().toLowerCase();

  console.log("formatUsername output", username);
  return username;
}

This is not production-grade logging. It is learning-grade instrumentation.

The learner can see the boundary of the function. They can tell whether the bug is before the function, inside it, or after it.

That is a huge step up from staring at a final broken UI and guessing.

The Console Can Teach Event Flow

The DOM is where console.log becomes especially helpful.

const form = document.querySelector("form");
const input = document.querySelector("input");

form.addEventListener("submit", (event) => {
  event.preventDefault();
  console.log("submitted value", input.value);
});

That log tells the learner several things:

  1. The form listener is attached.
  2. The submit event fired.
  3. The input had a value at that moment.
  4. The value is a string.

If nothing appears, the question changes. Was the form selected? Did the button submit the form? Did the script run before the DOM existed?

Those are real debugging questions. They are also much easier to ask when the learner has permission to inspect the program.

For DOM bugs, logging selected elements is often the first clean signal:

const button = document.querySelector("#save");
console.log(button);

If the console shows null, the learner has learned something specific. The click handler is not the first problem. The selector or script timing is.

That can send them toward a focused explanation like why querySelector returns null, instead of another hour of random changes.

When To Move Beyond console.log

None of this means console.log is the only debugging tool worth learning.

Breakpoints, the debugger statement, network panels, stack traces, test output, and browser inspectors all matter. Learners should grow into them.

But "use the debugger" is not automatically more educational if the learner cannot yet predict values, inspect state, or ask a good question.

console.log is often the simplest way to build those habits first.

The mature path is not:

Stop logging and become advanced.

It is:

Log deliberately.
Use better tools when they answer the question more clearly.
Clean up your logs when they have done their job.

That is a professional habit, not a beginner confession.

Key Takeaways

  • console.log is useful because it makes invisible values inspectable.
  • Bad logging dumps values without a question; good logging tests a hypothesis.
  • Learners should predict the output before running the code.
  • Function boundaries, transformations, conditionals, and event handlers are good places to log.
  • Moving beyond console.log should mean choosing better tools, not pretending inspection is childish.
Share this post: