Console.error, .warn, and .info
You'll learn how to use specialized console methods that categorize your messages by severity and make debugging easier.
Beyond console.log
While console.log works for general output, the console API provides three specialized logging methods that visually distinguish different types of messages: console.error(), console.warn(), and console.info().
Visual Categorization
Think of these methods like traffic lights for your code's messages:
console.error() – Red light. Signals errors and exceptions:
console.error('Failed to load user data');
console.error('Invalid API key:', apiKey);
Displays in red with an error icon. Browser consoles often include a stack trace automatically.
console.warn() – Yellow light. Highlights warnings or deprecated usage:
console.warn('This function will be removed in v2.0');
console.warn('Unusual input detected:', value);
Displays in yellow/orange with a warning icon.
console.info() – Blue/informational. Provides helpful context:
console.info('App initialized successfully');
console.info('Using API version:', apiVersion);
Displays with an info icon (styling varies by browser).
Filtering Benefits
The real power comes from browser DevTools. You can filter console output by type—showing only errors, hiding warnings, etc. This makes finding specific messages in a flood of logs much easier during debugging.
All three methods accept multiple arguments just like console.log, and format objects, arrays, and other data types the same way.
Key Takeaway: Use console.error(), console.warn(), and console.info() to categorize log messages by severity, making them easier to filter and identify in the browser console.