What is the Console API?
The Console API helps you inspect JavaScript while you are building a page. It writes information to the browser's developer tools instead of changing the page for visitors.
What you will learn
- How to open the browser's Console panel
- How to inspect values with
console.log() - Why developer output should not replace a user-facing message
Open the Console
Open the browser's developer tools with the menu or with Ctrl+Shift+I, then choose the Console tab. You can also right-click a page and choose Inspect. The exact menu label may differ between browsers.
Try console.log()
const userName = 'Yugien';
console.log('userName:', userName);
Run this code in the Console. The label makes the output easier to scan when several values are logged.
Read errors carefully
notDefinedFunction();
The Console reports that the function is not defined and points to a source location. Read the first useful error and its location before changing unrelated code.
Common mistakes
- Do not use Console output as the only feedback for visitors.
- Remove logs that expose private data before publishing.
- Use breakpoints and the debugger when repeated logging is not enough.