Course contentsShow
← Web Development
Lesson 2244 of 2,98241. Debugging TechniquesFree lesson

console.warn and console.error

Learn to distinguish warnings from errors in the console for better issue prioritization.

Learn to Use console.warn and console.error for Smarter Debugging

You'll learn how to distinguish warnings from errors in your console output so you can prioritize fixes more effectively.

What They Do

Both console.warn() and console.error() send messages to the browser console—just like console.log()—but with critical differences in appearance and meaning:

  • console.warn() displays messages in yellow/orange with a warning icon, indicating something might be wrong but won't break your app immediately
  • console.error() displays messages in red with an error icon, signaling serious problems that need urgent attention

Why the Distinction Matters

Think of your console like a hospital triage system. Not every issue is life-threatening, and treating everything as equally urgent wastes time and creates noise.

Warnings are for deprecations, non-critical failures, or suspicious patterns:

if (!userEmail) {
  console.warn('User email missing - using default notification method');
}

Errors are for genuine failures that break functionality:

if (response.status === 500) {
  console.error('API request failed:', response.statusText);
}

Visual Filtering Advantage

DevTools lets you filter console output by type. When debugging, you can hide warnings and focus only on errors blocking your workflow—or vice versa when cleaning up code quality issues.

This categorization also helps teammates understand severity at a glance when reviewing logs, and production error monitoring tools often treat these levels differently for alerting purposes.

Key Takeaway: Use console.warn() for non-critical issues that deserve attention later and console.error() for serious problems requiring immediate fixes—your console becomes a prioritized task list instead of noise.