skip to content
dz

Back to the article · Zurück zum Artikel (Deutsch)

Example 01: What the console box mirrors

One page per example

Two console.log() calls and an uncaught error. The box on this page repeats them, so readers who do not open the console still see the output.

How to try it

  1. Open the console of the developer tools (F12, Cmd+Opt+I on a Mac) and compare it with the "Console output" box.
  2. The error appears in both. The box shows only its message.
Console output mirrored from console.log() and errors on this page, the same text as in the developer tools
Expected output what the lines above should say
a normal line
several values 42 null
Uncaught Error: an uncaught error, shown as well

The box mirrors console.log() and uncaught errors. console.warn() and the other methods stay in the console. The prefix before the error message depends on the browser.

Live example

Source

<script>
	console.log('a normal line');
	console.log('several', 'values', 42, null);

	setTimeout(() => {
		throw new Error('an uncaught error, shown as well');
	}, 0);
</script>