• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<html lang="en">
3<head>
4  <meta charset="utf-8">
5  <meta name="viewport" content="width=device-width">
6  <meta name="nodejs.org:node-version" content="v14.20.1">
7  <title>Console | Node.js v14.20.1 Documentation</title>
8  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic&display=fallback">
9  <link rel="stylesheet" href="assets/style.css">
10  <link rel="stylesheet" href="assets/hljs.css">
11  <link rel="canonical" href="https://nodejs.org/api/console.html">
12</head>
13<body class="alt apidoc" id="api-section-console">
14  <div id="content" class="clearfix">
15    <div id="column2" class="interior">
16      <div id="intro" class="interior">
17        <a href="/" title="Go back to the home page">
18          Node.js
19        </a>
20      </div>
21      <ul>
22<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
23<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
24</ul>
25<hr class="line">
26<ul>
27<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
28<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
29<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
30<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
31<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
32<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
33<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
34<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
35<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
36<li><a href="console.html" class="nav-console active">Console</a></li>
37<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
38<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
39<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
40<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
41<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
42<li><a href="dns.html" class="nav-dns">DNS</a></li>
43<li><a href="domain.html" class="nav-domain">Domain</a></li>
44<li><a href="errors.html" class="nav-errors">Errors</a></li>
45<li><a href="events.html" class="nav-events">Events</a></li>
46<li><a href="fs.html" class="nav-fs">File system</a></li>
47<li><a href="globals.html" class="nav-globals">Globals</a></li>
48<li><a href="http.html" class="nav-http">HTTP</a></li>
49<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
50<li><a href="https.html" class="nav-https">HTTPS</a></li>
51<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
52<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
53<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
54<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
55<li><a href="module.html" class="nav-module">Modules: <code>module</code> API</a></li>
56<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
57<li><a href="net.html" class="nav-net">Net</a></li>
58<li><a href="os.html" class="nav-os">OS</a></li>
59<li><a href="path.html" class="nav-path">Path</a></li>
60<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
61<li><a href="policy.html" class="nav-policy">Policies</a></li>
62<li><a href="process.html" class="nav-process">Process</a></li>
63<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
64<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
65<li><a href="readline.html" class="nav-readline">Readline</a></li>
66<li><a href="repl.html" class="nav-repl">REPL</a></li>
67<li><a href="report.html" class="nav-report">Report</a></li>
68<li><a href="stream.html" class="nav-stream">Stream</a></li>
69<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
70<li><a href="timers.html" class="nav-timers">Timers</a></li>
71<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
72<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
73<li><a href="tty.html" class="nav-tty">TTY</a></li>
74<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
75<li><a href="url.html" class="nav-url">URL</a></li>
76<li><a href="util.html" class="nav-util">Utilities</a></li>
77<li><a href="v8.html" class="nav-v8">V8</a></li>
78<li><a href="vm.html" class="nav-vm">VM</a></li>
79<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
80<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
81<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
82</ul>
83<hr class="line">
84<ul>
85<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
86</ul>
87    </div>
88
89    <div id="column1" data-id="console" class="interior">
90      <header>
91        <div class="header-container">
92          <h1>Node.js v14.20.1 documentation</h1>
93          <button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden>
94            <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
95              <path fill="none" d="M0 0h24v24H0z" />
96              <path d="M11.1 12.08c-2.33-4.51-.5-8.48.53-10.07C6.27 2.2 1.98 6.59 1.98 12c0 .14.02.28.02.42.62-.27 1.29-.42 2-.42 1.66 0 3.18.83 4.1 2.15A4.01 4.01 0 0111 18c0 1.52-.87 2.83-2.12 3.51.98.32 2.03.5 3.11.5 3.5 0 6.58-1.8 8.37-4.52-2.36.23-6.98-.97-9.26-5.41z"/>
97              <path d="M7 16h-.18C6.4 14.84 5.3 14 4 14c-1.66 0-3 1.34-3 3s1.34 3 3 3h3c1.1 0 2-.9 2-2s-.9-2-2-2z"/>
98            </svg>
99            <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
100              <path d="M0 0h24v24H0z" fill="none" />
101              <path d="M6.76 4.84l-1.8-1.79-1.41 1.41 1.79 1.79 1.42-1.41zM4 10.5H1v2h3v-2zm9-9.95h-2V3.5h2V.55zm7.45 3.91l-1.41-1.41-1.79 1.79 1.41 1.41 1.79-1.79zm-3.21 13.7l1.79 1.8 1.41-1.41-1.8-1.79-1.4 1.4zM20 10.5v2h3v-2h-3zm-8-5c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm-1 16.95h2V19.5h-2v2.95zm-7.45-3.91l1.41 1.41 1.79-1.8-1.41-1.41-1.79 1.8z"/>
102            </svg>
103          </button>
104        </div>
105        <div id="gtoc">
106          <ul>
107            <li>
108              <a href="index.html">Index</a>
109            </li>
110            <li>
111              <a href="all.html">View on single page</a>
112            </li>
113            <li>
114              <a href="console.json">View as JSON</a>
115            </li>
116
117    <li class="version-picker">
118      <a href="#">View another version <span>&#x25bc;</span></a>
119      <ol class="version-picker"><li><a href="https://nodejs.org/docs/latest-v18.x/api/console.html">18.x</a></li>
120<li><a href="https://nodejs.org/docs/latest-v17.x/api/console.html">17.x</a></li>
121<li><a href="https://nodejs.org/docs/latest-v16.x/api/console.html">16.x <b>LTS</b></a></li>
122<li><a href="https://nodejs.org/docs/latest-v15.x/api/console.html">15.x</a></li>
123<li><a href="https://nodejs.org/docs/latest-v14.x/api/console.html">14.x <b>LTS</b></a></li>
124<li><a href="https://nodejs.org/docs/latest-v13.x/api/console.html">13.x</a></li>
125<li><a href="https://nodejs.org/docs/latest-v12.x/api/console.html">12.x <b>LTS</b></a></li>
126<li><a href="https://nodejs.org/docs/latest-v11.x/api/console.html">11.x</a></li>
127<li><a href="https://nodejs.org/docs/latest-v10.x/api/console.html">10.x</a></li>
128<li><a href="https://nodejs.org/docs/latest-v9.x/api/console.html">9.x</a></li>
129<li><a href="https://nodejs.org/docs/latest-v8.x/api/console.html">8.x</a></li>
130<li><a href="https://nodejs.org/docs/latest-v7.x/api/console.html">7.x</a></li>
131<li><a href="https://nodejs.org/docs/latest-v6.x/api/console.html">6.x</a></li>
132<li><a href="https://nodejs.org/docs/latest-v5.x/api/console.html">5.x</a></li>
133<li><a href="https://nodejs.org/docs/latest-v4.x/api/console.html">4.x</a></li>
134<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/console.html">0.12.x</a></li>
135<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/console.html">0.10.x</a></li></ol>
136    </li>
137
138            <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/console.md">Edit on GitHub</a></li>
139          </ul>
140        </div>
141        <hr>
142      </header>
143
144      <details id="toc" open><summary>Table of contents</summary><ul>
145<li><span class="stability_2"><a href="#console_console">Console</a></span>
146<ul>
147<li><a href="#console_class_console">Class: <code>Console</code></a>
148<ul>
149<li><a href="#console_new_console_stdout_stderr_ignoreerrors"><code>new Console(stdout[, stderr][, ignoreErrors])</code></a></li>
150<li><a href="#console_new_console_options"><code>new Console(options)</code></a></li>
151<li><a href="#console_console_assert_value_message"><code>console.assert(value[, ...message])</code></a></li>
152<li><a href="#console_console_clear"><code>console.clear()</code></a></li>
153<li><a href="#console_console_count_label"><code>console.count([label])</code></a></li>
154<li><a href="#console_console_countreset_label"><code>console.countReset([label])</code></a></li>
155<li><a href="#console_console_debug_data_args"><code>console.debug(data[, ...args])</code></a></li>
156<li><a href="#console_console_dir_obj_options"><code>console.dir(obj[, options])</code></a></li>
157<li><a href="#console_console_dirxml_data"><code>console.dirxml(...data)</code></a></li>
158<li><a href="#console_console_error_data_args"><code>console.error([data][, ...args])</code></a></li>
159<li><a href="#console_console_group_label"><code>console.group([...label])</code></a></li>
160<li><a href="#console_console_groupcollapsed"><code>console.groupCollapsed()</code></a></li>
161<li><a href="#console_console_groupend"><code>console.groupEnd()</code></a></li>
162<li><a href="#console_console_info_data_args"><code>console.info([data][, ...args])</code></a></li>
163<li><a href="#console_console_log_data_args"><code>console.log([data][, ...args])</code></a></li>
164<li><a href="#console_console_table_tabulardata_properties"><code>console.table(tabularData[, properties])</code></a></li>
165<li><a href="#console_console_time_label"><code>console.time([label])</code></a></li>
166<li><a href="#console_console_timeend_label"><code>console.timeEnd([label])</code></a></li>
167<li><a href="#console_console_timelog_label_data"><code>console.timeLog([label][, ...data])</code></a></li>
168<li><a href="#console_console_trace_message_args"><code>console.trace([message][, ...args])</code></a></li>
169<li><a href="#console_console_warn_data_args"><code>console.warn([data][, ...args])</code></a></li>
170</ul>
171</li>
172<li><a href="#console_inspector_only_methods">Inspector only methods</a>
173<ul>
174<li><a href="#console_console_profile_label"><code>console.profile([label])</code></a></li>
175<li><a href="#console_console_profileend_label"><code>console.profileEnd([label])</code></a></li>
176<li><a href="#console_console_timestamp_label"><code>console.timeStamp([label])</code></a></li>
177</ul>
178</li>
179</ul>
180</li>
181</ul></details>
182
183      <div id="apicontent">
184        <h2>Console<span><a class="mark" href="#console_console" id="console_console">#</a></span></h2>
185
186<p></p><div class="api_stability api_stability_2"><a href="documentation.html#documentation_stability_index">Stability: 2</a> - Stable</div><p></p>
187<p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v14.20.1/lib/console.js">lib/console.js</a></p>
188<p>The <code>console</code> module provides a simple debugging console that is similar to the
189JavaScript console mechanism provided by web browsers.</p>
190<p>The module exports two specific components:</p>
191<ul>
192<li>A <code>Console</code> class with methods such as <code>console.log()</code>, <code>console.error()</code> and
193<code>console.warn()</code> that can be used to write to any Node.js stream.</li>
194<li>A global <code>console</code> instance configured to write to <a href="process.html#process_process_stdout"><code>process.stdout</code></a> and
195<a href="process.html#process_process_stderr"><code>process.stderr</code></a>. The global <code>console</code> can be used without calling
196<code>require('console')</code>.</li>
197</ul>
198<p><em><strong>Warning</strong></em>: The global console object's methods are neither consistently
199synchronous like the browser APIs they resemble, nor are they consistently
200asynchronous like all other Node.js streams. See the <a href="process.html#process_a_note_on_process_i_o">note on process I/O</a> for
201more information.</p>
202<p>Example using the global <code>console</code>:</p>
203<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'hello world'</span>);
204<span class="hljs-comment">// Prints: hello world, to stdout</span>
205<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'hello %s'</span>, <span class="hljs-string">'world'</span>);
206<span class="hljs-comment">// Prints: hello world, to stdout</span>
207<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>(<span class="hljs-string">'Whoops, something bad happened'</span>));
208<span class="hljs-comment">// Prints error message and stack trace to stderr:</span>
209<span class="hljs-comment">//   Error: Whoops, something bad happened</span>
210<span class="hljs-comment">//     at [eval]:5:15</span>
211<span class="hljs-comment">//     at Script.runInThisContext (node:vm:132:18)</span>
212<span class="hljs-comment">//     at Object.runInThisContext (node:vm:309:38)</span>
213<span class="hljs-comment">//     at node:internal/process/execution:77:19</span>
214<span class="hljs-comment">//     at [eval]-wrapper:6:22</span>
215<span class="hljs-comment">//     at evalScript (node:internal/process/execution:76:60)</span>
216<span class="hljs-comment">//     at node:internal/main/eval_string:23:3</span>
217
218<span class="hljs-keyword">const</span> name = <span class="hljs-string">'Will Robinson'</span>;
219<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(<span class="hljs-string">`Danger <span class="hljs-subst">${name}</span>! Danger!`</span>);
220<span class="hljs-comment">// Prints: Danger Will Robinson! Danger!, to stderr</span></code></pre>
221<p>Example using the <code>Console</code> class:</p>
222<pre><code class="language-js"><span class="hljs-keyword">const</span> out = <span class="hljs-title function_">getStreamSomehow</span>();
223<span class="hljs-keyword">const</span> err = <span class="hljs-title function_">getStreamSomehow</span>();
224<span class="hljs-keyword">const</span> myConsole = <span class="hljs-keyword">new</span> <span class="hljs-variable language_">console</span>.<span class="hljs-title class_">Console</span>(out, err);
225
226myConsole.<span class="hljs-title function_">log</span>(<span class="hljs-string">'hello world'</span>);
227<span class="hljs-comment">// Prints: hello world, to out</span>
228myConsole.<span class="hljs-title function_">log</span>(<span class="hljs-string">'hello %s'</span>, <span class="hljs-string">'world'</span>);
229<span class="hljs-comment">// Prints: hello world, to out</span>
230myConsole.<span class="hljs-title function_">error</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>(<span class="hljs-string">'Whoops, something bad happened'</span>));
231<span class="hljs-comment">// Prints: [Error: Whoops, something bad happened], to err</span>
232
233<span class="hljs-keyword">const</span> name = <span class="hljs-string">'Will Robinson'</span>;
234myConsole.<span class="hljs-title function_">warn</span>(<span class="hljs-string">`Danger <span class="hljs-subst">${name}</span>! Danger!`</span>);
235<span class="hljs-comment">// Prints: Danger Will Robinson! Danger!, to err</span></code></pre>
236<section><h3>Class: <code>Console</code><span><a class="mark" href="#console_class_console" id="console_class_console">#</a></span></h3>
237<div class="api_metadata">
238<details class="changelog"><summary>History</summary>
239<table>
240<tbody><tr><th>Version</th><th>Changes</th></tr>
241<tr><td>v8.0.0</td>
242<td><p>Errors that occur while writing to the underlying streams will now be ignored by default.</p></td></tr>
243</tbody></table>
244</details>
245</div>
246
247<p>The <code>Console</code> class can be used to create a simple logger with configurable
248output streams and can be accessed using either <code>require('console').Console</code>
249or <code>console.Console</code> (or their destructured counterparts):</p>
250<pre><code class="language-js"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">Console</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'console'</span>);</code></pre>
251<pre><code class="language-js"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">Console</span> } = <span class="hljs-variable language_">console</span>;</code></pre>
252<h4><code>new Console(stdout[, stderr][, ignoreErrors])</code><span><a class="mark" href="#console_new_console_stdout_stderr_ignoreerrors" id="console_new_console_stdout_stderr_ignoreerrors">#</a></span></h4>
253<h4><code>new Console(options)</code><span><a class="mark" href="#console_new_console_options" id="console_new_console_options">#</a></span></h4>
254<div class="api_metadata">
255<details class="changelog"><summary>History</summary>
256<table>
257<tbody><tr><th>Version</th><th>Changes</th></tr>
258<tr><td>v14.2.0</td>
259<td><p>The <code>groupIndentation</code> option was introduced.</p></td></tr>
260<tr><td>v11.7.0</td>
261<td><p>The <code>inspectOptions</code> option is introduced.</p></td></tr>
262<tr><td>v10.0.0</td>
263<td><p>The <code>Console</code> constructor now supports an <code>options</code> argument, and the <code>colorMode</code> option was introduced.</p></td></tr>
264<tr><td>v8.0.0</td>
265<td><p>The <code>ignoreErrors</code> option was introduced.</p></td></tr>
266</tbody></table>
267</details>
268</div>
269<ul>
270<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
271<ul>
272<li><code>stdout</code> <a href="stream.html#stream_class_stream_writable" class="type">&#x3C;stream.Writable></a></li>
273<li><code>stderr</code> <a href="stream.html#stream_class_stream_writable" class="type">&#x3C;stream.Writable></a></li>
274<li><code>ignoreErrors</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> Ignore errors when writing to the underlying
275streams. <strong>Default:</strong> <code>true</code>.</li>
276<li><code>colorMode</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Set color support for this <code>Console</code> instance.
277Setting to <code>true</code> enables coloring while inspecting values. Setting to
278<code>false</code> disables coloring while inspecting values. Setting to
279<code>'auto'</code> makes color support depend on the value of the <code>isTTY</code> property
280and the value returned by <code>getColorDepth()</code> on the respective stream. This
281option can not be used, if <code>inspectOptions.colors</code> is set as well.
282<strong>Default:</strong> <code>'auto'</code>.</li>
283<li><code>inspectOptions</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> Specifies options that are passed along to
284<a href="util.html#util_util_inspect_object_options"><code>util.inspect()</code></a>.</li>
285<li><code>groupIndentation</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> Set group indentation.
286<strong>Default:</strong> <code>2</code>.</li>
287</ul>
288</li>
289</ul>
290<p>Creates a new <code>Console</code> with one or two writable stream instances. <code>stdout</code> is a
291writable stream to print log or info output. <code>stderr</code> is used for warning or
292error output. If <code>stderr</code> is not provided, <code>stdout</code> is used for <code>stderr</code>.</p>
293<pre><code class="language-js"><span class="hljs-keyword">const</span> output = fs.<span class="hljs-title function_">createWriteStream</span>(<span class="hljs-string">'./stdout.log'</span>);
294<span class="hljs-keyword">const</span> errorOutput = fs.<span class="hljs-title function_">createWriteStream</span>(<span class="hljs-string">'./stderr.log'</span>);
295<span class="hljs-comment">// Custom simple logger</span>
296<span class="hljs-keyword">const</span> logger = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Console</span>({ <span class="hljs-attr">stdout</span>: output, <span class="hljs-attr">stderr</span>: errorOutput });
297<span class="hljs-comment">// use it like console</span>
298<span class="hljs-keyword">const</span> count = <span class="hljs-number">5</span>;
299logger.<span class="hljs-title function_">log</span>(<span class="hljs-string">'count: %d'</span>, count);
300<span class="hljs-comment">// In stdout.log: count 5</span></code></pre>
301<p>The global <code>console</code> is a special <code>Console</code> whose output is sent to
302<a href="process.html#process_process_stdout"><code>process.stdout</code></a> and <a href="process.html#process_process_stderr"><code>process.stderr</code></a>. It is equivalent to calling:</p>
303<pre><code class="language-js"><span class="hljs-keyword">new</span> <span class="hljs-title class_">Console</span>({ <span class="hljs-attr">stdout</span>: process.<span class="hljs-property">stdout</span>, <span class="hljs-attr">stderr</span>: process.<span class="hljs-property">stderr</span> });</code></pre>
304<h4><code>console.assert(value[, ...message])</code><span><a class="mark" href="#console_console_assert_value_message" id="console_console_assert_value_message">#</a></span></h4>
305<div class="api_metadata">
306<details class="changelog"><summary>History</summary>
307<table>
308<tbody><tr><th>Version</th><th>Changes</th></tr>
309<tr><td>v10.0.0</td>
310<td><p>The implementation is now spec compliant and does not throw anymore.</p></td></tr>
311<tr><td>v0.1.101</td>
312<td><p><span>Added in: v0.1.101</span></p></td></tr>
313</tbody></table>
314</details>
315</div>
316<ul>
317<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> The value tested for being truthy.</li>
318<li><code>...message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> All arguments besides <code>value</code> are used as error message.</li>
319</ul>
320<p><code>console.assert()</code> writes a message if <code>value</code> is <a href="https://developer.mozilla.org/en-US/docs/Glossary/Falsy">falsy</a> or omitted. It only
321writes a message and does not otherwise affect execution. The output always
322starts with <code>"Assertion failed"</code>. If provided, <code>message</code> is formatted using
323<a href="util.html#util_util_format_format_args"><code>util.format()</code></a>.</p>
324<p>If <code>value</code> is <a href="https://developer.mozilla.org/en-US/docs/Glossary/Truthy">truthy</a>, nothing happens.</p>
325<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">assert</span>(<span class="hljs-literal">true</span>, <span class="hljs-string">'does nothing'</span>);
326
327<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">assert</span>(<span class="hljs-literal">false</span>, <span class="hljs-string">'Whoops %s work'</span>, <span class="hljs-string">'didn\'t'</span>);
328<span class="hljs-comment">// Assertion failed: Whoops didn't work</span>
329
330<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">assert</span>();
331<span class="hljs-comment">// Assertion failed</span></code></pre>
332<h4><code>console.clear()</code><span><a class="mark" href="#console_console_clear" id="console_console_clear">#</a></span></h4>
333<div class="api_metadata">
334<span>Added in: v8.3.0</span>
335</div>
336<p>When <code>stdout</code> is a TTY, calling <code>console.clear()</code> will attempt to clear the
337TTY. When <code>stdout</code> is not a TTY, this method does nothing.</p>
338<p>The specific operation of <code>console.clear()</code> can vary across operating systems
339and terminal types. For most Linux operating systems, <code>console.clear()</code>
340operates similarly to the <code>clear</code> shell command. On Windows, <code>console.clear()</code>
341will clear only the output in the current terminal viewport for the Node.js
342binary.</p>
343<h4><code>console.count([label])</code><span><a class="mark" href="#console_console_count_label" id="console_console_count_label">#</a></span></h4>
344<div class="api_metadata">
345<span>Added in: v8.3.0</span>
346</div>
347<ul>
348<li><code>label</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> The display label for the counter. <strong>Default:</strong> <code>'default'</code>.</li>
349</ul>
350<p>Maintains an internal counter specific to <code>label</code> and outputs to <code>stdout</code> the
351number of times <code>console.count()</code> has been called with the given <code>label</code>.</p>
352<!-- eslint-skip -->
353<pre><code class="language-js">> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">count</span>()
354<span class="hljs-attr">default</span>: <span class="hljs-number">1</span>
355<span class="hljs-literal">undefined</span>
356> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">count</span>(<span class="hljs-string">'default'</span>)
357<span class="hljs-attr">default</span>: <span class="hljs-number">2</span>
358<span class="hljs-literal">undefined</span>
359> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">count</span>(<span class="hljs-string">'abc'</span>)
360<span class="hljs-attr">abc</span>: <span class="hljs-number">1</span>
361<span class="hljs-literal">undefined</span>
362> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">count</span>(<span class="hljs-string">'xyz'</span>)
363<span class="hljs-attr">xyz</span>: <span class="hljs-number">1</span>
364<span class="hljs-literal">undefined</span>
365> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">count</span>(<span class="hljs-string">'abc'</span>)
366<span class="hljs-attr">abc</span>: <span class="hljs-number">2</span>
367<span class="hljs-literal">undefined</span>
368> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">count</span>()
369<span class="hljs-attr">default</span>: <span class="hljs-number">3</span>
370<span class="hljs-literal">undefined</span>
371></code></pre>
372<h4><code>console.countReset([label])</code><span><a class="mark" href="#console_console_countreset_label" id="console_console_countreset_label">#</a></span></h4>
373<div class="api_metadata">
374<span>Added in: v8.3.0</span>
375</div>
376<ul>
377<li><code>label</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> The display label for the counter. <strong>Default:</strong> <code>'default'</code>.</li>
378</ul>
379<p>Resets the internal counter specific to <code>label</code>.</p>
380<!-- eslint-skip -->
381<pre><code class="language-js">> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">count</span>(<span class="hljs-string">'abc'</span>);
382<span class="hljs-attr">abc</span>: <span class="hljs-number">1</span>
383<span class="hljs-literal">undefined</span>
384> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">countReset</span>(<span class="hljs-string">'abc'</span>);
385<span class="hljs-literal">undefined</span>
386> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">count</span>(<span class="hljs-string">'abc'</span>);
387<span class="hljs-attr">abc</span>: <span class="hljs-number">1</span>
388<span class="hljs-literal">undefined</span>
389></code></pre>
390<h4><code>console.debug(data[, ...args])</code><span><a class="mark" href="#console_console_debug_data_args" id="console_console_debug_data_args">#</a></span></h4>
391<div class="api_metadata">
392<details class="changelog"><summary>History</summary>
393<table>
394<tbody><tr><th>Version</th><th>Changes</th></tr>
395<tr><td>v8.10.0</td>
396<td><p><code>console.debug</code> is now an alias for <code>console.log</code>.</p></td></tr>
397<tr><td>v8.0.0</td>
398<td><p><span>Added in: v8.0.0</span></p></td></tr>
399</tbody></table>
400</details>
401</div>
402<ul>
403<li><code>data</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
404<li><code>...args</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
405</ul>
406<p>The <code>console.debug()</code> function is an alias for <a href="#console_console_log_data_args"><code>console.log()</code></a>.</p>
407<h4><code>console.dir(obj[, options])</code><span><a class="mark" href="#console_console_dir_obj_options" id="console_console_dir_obj_options">#</a></span></h4>
408<div class="api_metadata">
409<span>Added in: v0.1.101</span>
410</div>
411<ul>
412<li><code>obj</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
413<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
414<ul>
415<li><code>showHidden</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> If <code>true</code> then the object's non-enumerable and symbol
416properties will be shown too. <strong>Default:</strong> <code>false</code>.</li>
417<li><code>depth</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> Tells <a href="util.html#util_util_inspect_object_options"><code>util.inspect()</code></a> how many times to recurse while
418formatting the object. This is useful for inspecting large complicated
419objects. To make it recurse indefinitely, pass <code>null</code>. <strong>Default:</strong> <code>2</code>.</li>
420<li><code>colors</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> If <code>true</code>, then the output will be styled with ANSI color
421codes. Colors are customizable;
422see <a href="util.html#util_customizing_util_inspect_colors">customizing <code>util.inspect()</code> colors</a>. <strong>Default:</strong> <code>false</code>.</li>
423</ul>
424</li>
425</ul>
426<p>Uses <a href="util.html#util_util_inspect_object_options"><code>util.inspect()</code></a> on <code>obj</code> and prints the resulting string to <code>stdout</code>.
427This function bypasses any custom <code>inspect()</code> function defined on <code>obj</code>.</p>
428<h4><code>console.dirxml(...data)</code><span><a class="mark" href="#console_console_dirxml_data" id="console_console_dirxml_data">#</a></span></h4>
429<div class="api_metadata">
430<details class="changelog"><summary>History</summary>
431<table>
432<tbody><tr><th>Version</th><th>Changes</th></tr>
433<tr><td>v9.3.0</td>
434<td><p><code>console.dirxml</code> now calls <code>console.log</code> for its arguments.</p></td></tr>
435<tr><td>v8.0.0</td>
436<td><p><span>Added in: v8.0.0</span></p></td></tr>
437</tbody></table>
438</details>
439</div>
440<ul>
441<li><code>...data</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
442</ul>
443<p>This method calls <code>console.log()</code> passing it the arguments received.
444This method does not produce any XML formatting.</p>
445<h4><code>console.error([data][, ...args])</code><span><a class="mark" href="#console_console_error_data_args" id="console_console_error_data_args">#</a></span></h4>
446<div class="api_metadata">
447<span>Added in: v0.1.100</span>
448</div>
449<ul>
450<li><code>data</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
451<li><code>...args</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
452</ul>
453<p>Prints to <code>stderr</code> with newline. Multiple arguments can be passed, with the
454first used as the primary message and all additional used as substitution
455values similar to <a href="http://man7.org/linux/man-pages/man3/printf.3.html"><code>printf(3)</code></a> (the arguments are all passed to
456<a href="util.html#util_util_format_format_args"><code>util.format()</code></a>).</p>
457<pre><code class="language-js"><span class="hljs-keyword">const</span> code = <span class="hljs-number">5</span>;
458<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'error #%d'</span>, code);
459<span class="hljs-comment">// Prints: error #5, to stderr</span>
460<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'error'</span>, code);
461<span class="hljs-comment">// Prints: error 5, to stderr</span></code></pre>
462<p>If formatting elements (e.g. <code>%d</code>) are not found in the first string then
463<a href="util.html#util_util_inspect_object_options"><code>util.inspect()</code></a> is called on each argument and the resulting string
464values are concatenated. See <a href="util.html#util_util_format_format_args"><code>util.format()</code></a> for more information.</p>
465<h4><code>console.group([...label])</code><span><a class="mark" href="#console_console_group_label" id="console_console_group_label">#</a></span></h4>
466<div class="api_metadata">
467<span>Added in: v8.5.0</span>
468</div>
469<ul>
470<li><code>...label</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
471</ul>
472<p>Increases indentation of subsequent lines by spaces for <code>groupIndentation</code>
473length.</p>
474<p>If one or more <code>label</code>s are provided, those are printed first without the
475additional indentation.</p>
476<h4><code>console.groupCollapsed()</code><span><a class="mark" href="#console_console_groupcollapsed" id="console_console_groupcollapsed">#</a></span></h4>
477<div class="api_metadata">
478<span>Added in: v8.5.0</span>
479</div>
480<p>An alias for <a href="#console_console_group_label"><code>console.group()</code></a>.</p>
481<h4><code>console.groupEnd()</code><span><a class="mark" href="#console_console_groupend" id="console_console_groupend">#</a></span></h4>
482<div class="api_metadata">
483<span>Added in: v8.5.0</span>
484</div>
485<p>Decreases indentation of subsequent lines by spaces for <code>groupIndentation</code>
486length.</p>
487<h4><code>console.info([data][, ...args])</code><span><a class="mark" href="#console_console_info_data_args" id="console_console_info_data_args">#</a></span></h4>
488<div class="api_metadata">
489<span>Added in: v0.1.100</span>
490</div>
491<ul>
492<li><code>data</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
493<li><code>...args</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
494</ul>
495<p>The <code>console.info()</code> function is an alias for <a href="#console_console_log_data_args"><code>console.log()</code></a>.</p>
496<h4><code>console.log([data][, ...args])</code><span><a class="mark" href="#console_console_log_data_args" id="console_console_log_data_args">#</a></span></h4>
497<div class="api_metadata">
498<span>Added in: v0.1.100</span>
499</div>
500<ul>
501<li><code>data</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
502<li><code>...args</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
503</ul>
504<p>Prints to <code>stdout</code> with newline. Multiple arguments can be passed, with the
505first used as the primary message and all additional used as substitution
506values similar to <a href="http://man7.org/linux/man-pages/man3/printf.3.html"><code>printf(3)</code></a> (the arguments are all passed to
507<a href="util.html#util_util_format_format_args"><code>util.format()</code></a>).</p>
508<pre><code class="language-js"><span class="hljs-keyword">const</span> count = <span class="hljs-number">5</span>;
509<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'count: %d'</span>, count);
510<span class="hljs-comment">// Prints: count: 5, to stdout</span>
511<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'count:'</span>, count);
512<span class="hljs-comment">// Prints: count: 5, to stdout</span></code></pre>
513<p>See <a href="util.html#util_util_format_format_args"><code>util.format()</code></a> for more information.</p>
514<h4><code>console.table(tabularData[, properties])</code><span><a class="mark" href="#console_console_table_tabulardata_properties" id="console_console_table_tabulardata_properties">#</a></span></h4>
515<div class="api_metadata">
516<span>Added in: v10.0.0</span>
517</div>
518<ul>
519<li><code>tabularData</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
520<li><code>properties</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a> Alternate properties for constructing the table.</li>
521</ul>
522<p>Try to construct a table with the columns of the properties of <code>tabularData</code>
523(or use <code>properties</code>) and rows of <code>tabularData</code> and log it. Falls back to just
524logging the argument if it can’t be parsed as tabular.</p>
525<pre><code class="language-js"><span class="hljs-comment">// These can't be parsed as tabular data</span>
526<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">table</span>(<span class="hljs-title class_">Symbol</span>());
527<span class="hljs-comment">// Symbol()</span>
528
529<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">table</span>(<span class="hljs-literal">undefined</span>);
530<span class="hljs-comment">// undefined</span>
531
532<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">table</span>([{ <span class="hljs-attr">a</span>: <span class="hljs-number">1</span>, <span class="hljs-attr">b</span>: <span class="hljs-string">'Y'</span> }, { <span class="hljs-attr">a</span>: <span class="hljs-string">'Z'</span>, <span class="hljs-attr">b</span>: <span class="hljs-number">2</span> }]);
533<span class="hljs-comment">// ┌─────────┬─────┬─────┐</span>
534<span class="hljs-comment">// │ (index) │  a  │  b  │</span>
535<span class="hljs-comment">// ├─────────┼─────┼─────┤</span>
536<span class="hljs-comment">// │    0    │  1  │ 'Y' │</span>
537<span class="hljs-comment">// │    1    │ 'Z' │  2  │</span>
538<span class="hljs-comment">// └─────────┴─────┴─────┘</span>
539
540<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">table</span>([{ <span class="hljs-attr">a</span>: <span class="hljs-number">1</span>, <span class="hljs-attr">b</span>: <span class="hljs-string">'Y'</span> }, { <span class="hljs-attr">a</span>: <span class="hljs-string">'Z'</span>, <span class="hljs-attr">b</span>: <span class="hljs-number">2</span> }], [<span class="hljs-string">'a'</span>]);
541<span class="hljs-comment">// ┌─────────┬─────┐</span>
542<span class="hljs-comment">// │ (index) │  a  │</span>
543<span class="hljs-comment">// ├─────────┼─────┤</span>
544<span class="hljs-comment">// │    0    │  1  │</span>
545<span class="hljs-comment">// │    1    │ 'Z' │</span>
546<span class="hljs-comment">// └─────────┴─────┘</span></code></pre>
547<h4><code>console.time([label])</code><span><a class="mark" href="#console_console_time_label" id="console_console_time_label">#</a></span></h4>
548<div class="api_metadata">
549<span>Added in: v0.1.104</span>
550</div>
551<ul>
552<li><code>label</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> <strong>Default:</strong> <code>'default'</code></li>
553</ul>
554<p>Starts a timer that can be used to compute the duration of an operation. Timers
555are identified by a unique <code>label</code>. Use the same <code>label</code> when calling
556<a href="#console_console_timeend_label"><code>console.timeEnd()</code></a> to stop the timer and output the elapsed time in
557suitable time units to <code>stdout</code>. For example, if the elapsed
558time is 3869ms, <code>console.timeEnd()</code> displays "3.869s".</p>
559<h4><code>console.timeEnd([label])</code><span><a class="mark" href="#console_console_timeend_label" id="console_console_timeend_label">#</a></span></h4>
560<div class="api_metadata">
561<details class="changelog"><summary>History</summary>
562<table>
563<tbody><tr><th>Version</th><th>Changes</th></tr>
564<tr><td>v13.0.0</td>
565<td><p>The elapsed time is displayed with a suitable time unit.</p></td></tr>
566<tr><td>v6.0.0</td>
567<td><p>This method no longer supports multiple calls that don’t map to individual <code>console.time()</code> calls; see below for details.</p></td></tr>
568<tr><td>v0.1.104</td>
569<td><p><span>Added in: v0.1.104</span></p></td></tr>
570</tbody></table>
571</details>
572</div>
573<ul>
574<li><code>label</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> <strong>Default:</strong> <code>'default'</code></li>
575</ul>
576<p>Stops a timer that was previously started by calling <a href="#console_console_time_label"><code>console.time()</code></a> and
577prints the result to <code>stdout</code>:</p>
578<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">time</span>(<span class="hljs-string">'100-elements'</span>);
579<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &#x3C; <span class="hljs-number">100</span>; i++) {}
580<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">timeEnd</span>(<span class="hljs-string">'100-elements'</span>);
581<span class="hljs-comment">// prints 100-elements: 225.438ms</span></code></pre>
582<h4><code>console.timeLog([label][, ...data])</code><span><a class="mark" href="#console_console_timelog_label_data" id="console_console_timelog_label_data">#</a></span></h4>
583<div class="api_metadata">
584<span>Added in: v10.7.0</span>
585</div>
586<ul>
587<li><code>label</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> <strong>Default:</strong> <code>'default'</code></li>
588<li><code>...data</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
589</ul>
590<p>For a timer that was previously started by calling <a href="#console_console_time_label"><code>console.time()</code></a>, prints
591the elapsed time and other <code>data</code> arguments to <code>stdout</code>:</p>
592<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">time</span>(<span class="hljs-string">'process'</span>);
593<span class="hljs-keyword">const</span> value = <span class="hljs-title function_">expensiveProcess1</span>(); <span class="hljs-comment">// Returns 42</span>
594<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">timeLog</span>(<span class="hljs-string">'process'</span>, value);
595<span class="hljs-comment">// Prints "process: 365.227ms 42".</span>
596<span class="hljs-title function_">doExpensiveProcess2</span>(value);
597<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">timeEnd</span>(<span class="hljs-string">'process'</span>);</code></pre>
598<h4><code>console.trace([message][, ...args])</code><span><a class="mark" href="#console_console_trace_message_args" id="console_console_trace_message_args">#</a></span></h4>
599<div class="api_metadata">
600<span>Added in: v0.1.104</span>
601</div>
602<ul>
603<li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
604<li><code>...args</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
605</ul>
606<p>Prints to <code>stderr</code> the string <code>'Trace: '</code>, followed by the <a href="util.html#util_util_format_format_args"><code>util.format()</code></a>
607formatted message and stack trace to the current position in the code.</p>
608<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">trace</span>(<span class="hljs-string">'Show me'</span>);
609<span class="hljs-comment">// Prints: (stack trace will vary based on where trace is called)</span>
610<span class="hljs-comment">//  Trace: Show me</span>
611<span class="hljs-comment">//    at repl:2:9</span>
612<span class="hljs-comment">//    at REPLServer.defaultEval (repl.js:248:27)</span>
613<span class="hljs-comment">//    at bound (domain.js:287:14)</span>
614<span class="hljs-comment">//    at REPLServer.runBound [as eval] (domain.js:300:12)</span>
615<span class="hljs-comment">//    at REPLServer.&#x3C;anonymous> (repl.js:412:12)</span>
616<span class="hljs-comment">//    at emitOne (events.js:82:20)</span>
617<span class="hljs-comment">//    at REPLServer.emit (events.js:169:7)</span>
618<span class="hljs-comment">//    at REPLServer.Interface._onLine (readline.js:210:10)</span>
619<span class="hljs-comment">//    at REPLServer.Interface._line (readline.js:549:8)</span>
620<span class="hljs-comment">//    at REPLServer.Interface._ttyWrite (readline.js:826:14)</span></code></pre>
621<h4><code>console.warn([data][, ...args])</code><span><a class="mark" href="#console_console_warn_data_args" id="console_console_warn_data_args">#</a></span></h4>
622<div class="api_metadata">
623<span>Added in: v0.1.100</span>
624</div>
625<ul>
626<li><code>data</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
627<li><code>...args</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
628</ul>
629<p>The <code>console.warn()</code> function is an alias for <a href="#console_console_error_data_args"><code>console.error()</code></a>.</p>
630</section><section><h3>Inspector only methods<span><a class="mark" href="#console_inspector_only_methods" id="console_inspector_only_methods">#</a></span></h3>
631<p>The following methods are exposed by the V8 engine in the general API but do
632not display anything unless used in conjunction with the <a href="debugger.html">inspector</a>
633(<code>--inspect</code> flag).</p>
634<h4><code>console.profile([label])</code><span><a class="mark" href="#console_console_profile_label" id="console_console_profile_label">#</a></span></h4>
635<div class="api_metadata">
636<span>Added in: v8.0.0</span>
637</div>
638<ul>
639<li><code>label</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
640</ul>
641<p>This method does not display anything unless used in the inspector. The
642<code>console.profile()</code> method starts a JavaScript CPU profile with an optional
643label until <a href="#console_console_profileend_label"><code>console.profileEnd()</code></a> is called. The profile is then added to
644the <strong>Profile</strong> panel of the inspector.</p>
645<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">profile</span>(<span class="hljs-string">'MyLabel'</span>);
646<span class="hljs-comment">// Some code</span>
647<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">profileEnd</span>(<span class="hljs-string">'MyLabel'</span>);
648<span class="hljs-comment">// Adds the profile 'MyLabel' to the Profiles panel of the inspector.</span></code></pre>
649<h4><code>console.profileEnd([label])</code><span><a class="mark" href="#console_console_profileend_label" id="console_console_profileend_label">#</a></span></h4>
650<div class="api_metadata">
651<span>Added in: v8.0.0</span>
652</div>
653<ul>
654<li><code>label</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
655</ul>
656<p>This method does not display anything unless used in the inspector. Stops the
657current JavaScript CPU profiling session if one has been started and prints
658the report to the <strong>Profiles</strong> panel of the inspector. See
659<a href="#console_console_profile_label"><code>console.profile()</code></a> for an example.</p>
660<p>If this method is called without a label, the most recently started profile is
661stopped.</p>
662<h4><code>console.timeStamp([label])</code><span><a class="mark" href="#console_console_timestamp_label" id="console_console_timestamp_label">#</a></span></h4>
663<div class="api_metadata">
664<span>Added in: v8.0.0</span>
665</div>
666<ul>
667<li><code>label</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
668</ul>
669<p>This method does not display anything unless used in the inspector. The
670<code>console.timeStamp()</code> method adds an event with the label <code>'label'</code> to the
671<strong>Timeline</strong> panel of the inspector.</p></section>
672        <!-- API END -->
673      </div>
674    </div>
675  </div>
676  <script>
677    'use strict';
678    {
679      const kCustomPreference = 'customDarkTheme';
680      const userSettings = sessionStorage.getItem(kCustomPreference);
681      const themeToggleButton = document.getElementById('theme-toggle-btn');
682      if (userSettings === null && window.matchMedia) {
683        const mq = window.matchMedia('(prefers-color-scheme: dark)');
684        if ('onchange' in mq) {
685          function mqChangeListener(e) {
686            document.body.classList.toggle('dark-mode', e.matches);
687          }
688          mq.addEventListener('change', mqChangeListener);
689          if (themeToggleButton) {
690            themeToggleButton.addEventListener('click', function() {
691              mq.removeEventListener('change', mqChangeListener);
692            }, { once: true });
693          }
694        }
695        if (mq.matches) {
696          document.body.classList.add('dark-mode');
697        }
698      } else if (userSettings === 'true') {
699        document.body.classList.add('dark-mode');
700      }
701      if (themeToggleButton) {
702        themeToggleButton.hidden = false;
703        themeToggleButton.addEventListener('click', function() {
704          sessionStorage.setItem(
705            kCustomPreference,
706            document.body.classList.toggle('dark-mode')
707          );
708        });
709      }
710    }
711  </script>
712</body>
713</html>
714