Learning objective: Use console.log, console.warn, console.error, console.table and console.group to inspect values, and read output accurately (strings, numbers, arrays and objects).
The console is your window into a running program. console.log can print several values at once: separate them with commas and they appear on one line with spaces between.
Add a label to every value you print, such as console.log("total:", total). Without labels, a column of numbers quickly becomes impossible to read.
console.warn and console.error print in yellow and red. Use them for messages that need attention. console.table shows a list of records as a table, and console.group indents related lines.
Strings and numbers can look identical when printed on their own (5 and "5"). Inside a list, strings are shown with quotes, so ["5", 5] reveals the difference.
The Console API is defined by the WHATWG Console Standard and implemented by browsers and Node.js. Output formatting is implementation-specific; the academy's console uses its own deterministic format so that tests can compare output reliably.
In browser developer tools, logged objects are live references that can show their current state when expanded, not the state at logging time. Log JSON.stringify(obj) or a copy when you need a snapshot.
Log levels matter in production: errors and warnings are usually collected by monitoring tools, while debug logging is stripped or disabled. Logging is a diagnostic aid, not a substitute for tests or a debugger.
Use labels, console.table for collections, console.group for nested steps, and remove temporary logs before committing, or guard them behind a debug flag.
05Definitions
console.log
Prints values to the console, separated by spaces.
console.warn / console.error
Print a warning or an error message, shown in a different colour.
console.table
Prints a list of records as a table of rows and columns.
Label
A short piece of text printed next to a value so you know what the value is.
Log level
The importance of a console message: log, info, warn or error.
warn and error stand out from ordinary log lines. The academy console colours them, as browser tools do.
console.log("Checkout started");
console.warn("Only 2 items left in stock");
console.error("Payment failed: card declined");
console.info("Checkout will retry when the card is updated");
Sample input
None
Expected output
Checkout started
Only 2 items left in stock
Payment failed: card declined
Checkout will retry when the card is updated
Common mistake
Using console.error for ordinary messages, which hides real problems among noise.
Try this
Add a console.warn for a coupon that expires tomorrow.
ex-004-03Tables for collections Browser-executable JavaScript
console.table lays out a list of records as rows and columns. console.log shows the same data on one line. You will learn about lists (arrays) and records (objects) in Level 2.
When a cart total is wrong, professional developers do not guess. They log each intermediate value with a label (line totals, subtotal, discount, tax) and find the first value that is wrong. Stage 2 of the Shopping Cart project asks you to do this when one of its functions returns the wrong amount.
5. You want to see 20 product records as rows and columns. Which is the best choice?
console.error
console.table
console.group
console.count
6. What does console.groupEnd() do?
Deletes the grouped lines
Stops the indentation started by console.group
Ends the program
Prints the word end
13Solutions and tests
Each exercise's solution appears in the exercise once you have run its tests. Solutions are one possible answer: the tests accept any implementation with the same behaviour.
Automated acceptance tests for this lesson
These are the same checks the exercises run. They are visible on purpose: client-side tests help you learn and are not secret.
Label your output: Labelled area and perimeter; Still calculated from width and height
Warn when stock is low: Three lines at the right levels; Uses the stock value in the warning
A debug log for a cart: Prints the cart lines and total; Uses console.group and console.groupEnd; The total is calculated
ex-004-01: output matches the documented expected output
ex-004-02: output matches the documented expected output
ex-004-03: output matches the documented expected output
ex-004-04: output matches the documented expected output
The lesson lives in the companion repository at curriculum/level-01-foundations/module-01-discovering-javascript/lesson-004-using-the-console-and-understanding-output/. Every example on this page is generated from those files.
These links open the files in the GitHub repository (https://github.com/lsvekis/JavaScript-Professional-Engineering-Academy). You can also use the ZIP download above.
15Summary and next steps
Label every value you log.
Use warn and error for messages that need attention.
console.table shows records; console.group organises a trace.
Pass objects as separate arguments; joining them to strings with + hides their contents.
Copy a prompt into the AI assistant of your choice. Then verify what it says by running code here. No AI service is connected to this page.
DebuggingPlan my logging
Context: My shopping-cart total is wrong and I do not know which step fails.
Task: Suggest where to place labelled console.log lines to find the first wrong value.
Constraints: Do not fix the code; suggest at most five log lines with labels.
Expected behaviour: After running, I can point to the first incorrect value.
Testing: Ask me to paste the output and help me interpret it.
Concept explanationLog levels in real teams
Context: I know console.log, warn and error.
Task: Explain how professional teams use log levels in production applications.
Constraints: Under 200 words, no specific vendor products.
Expected behaviour: I can decide which level fits a message.
Testing: Give me five messages to classify.
Code reviewReview my debug output
Context: I wrote a 15-line debug log for a calculation.
Task: Review whether the labels and grouping make it easy to read.
Constraints: Suggest improvements without changing the calculation.
Expected behaviour: The output reads as a clear trace.
Testing: Show the improved output, not only the code.
Code predictionStrings or numbers?
Context: I am learning to read console output.
Task: Give me six console.log lines mixing strings, numbers and small lists, and ask me what each prints.
Constraints: Wait for my answers before revealing.
Expected behaviour: I can tell a string from a number in a list.
Testing: Explain each answer in one sentence.
TestingCheck log levels
Context: An exercise checks both the text and the level of my console messages.
Task: Explain why a test might check the log level as well as the text.
Constraints: Two short paragraphs.
Expected behaviour: I understand why level matters for monitoring.
Testing: Give one example of a production problem caused by the wrong level.