Console API
The Console API lets JavaScript send messages to the browser's developer tools, which makes program behavior easier to inspect.
What you will learn
- How to log a value while learning or debugging
- How errors and warnings differ from ordinary information
- Why console output is a development aid, not a user interface
Start with console.log()
const total = 2 + 3;
console.log('total:', total);Open the browser's developer tools and choose the Console tab to see the message. Logging a label beside the value makes output easier to scan.
Useful methods
console.log()- Shows general information while you inspect a program.
console.warn()- Highlights a condition that deserves attention but is not necessarily fatal.
console.error()- Reports an error or failed operation.
console.time()andconsole.timeEnd()- Measure the elapsed time between matching labels.
Common mistakes
- Remove temporary logs that expose private data before publishing.
- Do not rely on console output as the only feedback for a user.
- Read the first useful error and its source location before changing code randomly.
- Use breakpoints and the debugger when logging is not enough.