Learn
JavaScript console basics in the browser playground
Last updated: July 19, 2026
How to print values, structure debug output, and read the Output panel in Code Arena’s JavaScript editor — with habits that transfer to Node and browsers.
Why console.log still wins
In Code Arena, printed output comes from console methods that write to stdout. Start with a single log to confirm the sandbox is returning results before you chase logic bugs.
Debuggers are powerful, but playground scripts are usually short. A few well-placed logs are faster than configuring breakpoints for a ten-line experiment — and the same habit helps in CI logs and server processes later.
What to log (and what not to)
Log inputs at the boundary of a function, intermediate results before a branch, and the final value before return. Avoid logging entire huge objects on every loop iteration — you will flood Output and make the real signal hard to see.
For objects and arrays, JSON.stringify(value, null, 2) often reads better than the default object inspection in a plain stdout stream. For Errors, log error.message and error.stack when available.
- Label logs: console.log("total", total)
- Log types when confused: typeof x, Array.isArray(x)
- Prefer one clear story over twenty noisy lines
- Never log secrets, tokens, or personal data
A tiny debug loop
When a program misbehaves, change one thing at a time. Log just before the suspicious branch, Run, read Output, then adjust. This is slower than a full debugger on a large app, but perfect for short playground code.
If you are stuck, delete (or comment) half the program. If the bug disappears, it lived in the deleted half. Repeat. This binary-search approach feels crude and works surprisingly often.
- Log inputs of a function
- Log intermediate results
- Log the final value before return
- Remove logs once the bug is fixed so Share links stay clean
Errors vs output
If the process exits non-zero, Code Arena shows the error path. Read the message carefully — ReferenceError and TypeError usually point at a name or a null/undefined value.
SyntaxError means the parser never got a runnable program. Fix quotes, brackets, and commas first. Runtime errors mean the program started and then failed — your logs before the throw are gold.
Fix the first error you see; later errors often disappear. Chasing the third stack frame while the first line still throws wastes time.
console beyond log
console.warn and console.error are useful when you want severity in a longer script. console.table helps for small arrays of objects if the environment prints a readable table. In a minimal stdout capture, stick to log/warn/error and string labels if output looks flat.
Avoid relying on browser-only console UX (like interactive object expanders). Code Arena’s Output panel is closer to a terminal transcript than DevTools.
Try it
Open /javascript, replace the starter with a few labeled console.log lines, Run, then open the AST tab to see how ExpressionStatement nodes map to those logs. Add a deliberate ReferenceError, read Output, then fix it.