The console object provides access to the debugging console (e.g., the Web console in Firefox). The specifics of how it works vary from browser to browser or server runtimes (Node.js, for example), but there is a de facto set of features that are typically provided.
The console object can be accessed from any global object. Window on browsing scopes and WorkerGlobalScope as specific variants in workers via the property console. It's exposed as Window.console, and can be referenced as console. For example:
Note: Certain online IDEs and editors may implement the console API differently than the browsers. As a result, certain functionality of the console API, such as the timer methods, may not be outputted in the console of online IDEs or editors. Always open your browser's DevTools console to see the logs as shown in this documentation.
Creates a new inline group, indenting all following output by another level. However, unlike console.group() this starts with the inline group collapsed requiring the use of a disclosure button to expand it. To move back out a level, call console.groupEnd().
The console's most frequently used feature is logging text and other data. There are several categories of output you can generate using the console.log(), console.info(), console.warn(), console.error(), or console.debug() methods. Each of these results in output styled differently in the log, and you can use the filtering controls provided by your browser to view only the kinds of output that interest you.
You can use nested groups to help organize your output by visually combining related material. To create a new nested block, call console.group(). The console.groupCollapsed() method is similar but creates the new block collapsed, requiring the use of a disclosure button to open it for reading.
You can start a timer to calculate the duration of a specific operation. To start one, call the console.time() method, giving it a name as the only parameter. To stop the timer, and to get the elapsed time in milliseconds, just call the console.timeEnd() method, again passing the timer's name as the parameter. Up to 10,000 timers can run simultaneously on a given page.
Warning: The global console object's methods are neither consistentlysynchronous like the browser APIs they resemble, nor are they consistentlyasynchronous like all other Node.js streams. See the note on process I/O formore information.
The Console class can be used to create a simple logger with configurableoutput streams and can be accessed using either require('node:console').Consoleor console.Console (or their destructured counterparts):
console.assert() writes a message if value is falsy or omitted. It onlywrites a message and does not otherwise affect execution. The output alwaysstarts with "Assertion failed". If provided, message is formatted usingutil.format().
The specific operation of console.clear() can vary across operating systemsand terminal types. For most Linux operating systems, console.clear()operates similarly to the clear shell command. On Windows, console.clear()will clear only the output in the current terminal viewport for the Node.jsbinary.
Starts a timer that can be used to compute the duration of an operation. Timersare identified by a unique label. Use the same label when callingconsole.timeEnd() to stop the timer and output the elapsed time insuitable time units to stdout. For example, if the elapsedtime is 3869ms, console.timeEnd() displays "3.869s".
This method does not display anything unless used in the inspector. Theconsole.profile() method starts a JavaScript CPU profile with an optionallabel until console.profileEnd() is called. The profile is then added tothe Profile panel of the inspector.
This method does not display anything unless used in the inspector. Stops thecurrent JavaScript CPU profiling session if one has been started and printsthe report to the Profiles panel of the inspector. Seeconsole.profile() for an example.
An admin account has privileges to manage services for other people in your organization. The Admin console is only available when you're signed in to an admin account. If you don't have access to an admin account, get help from someone else who does. For details, see Who is my administrator?.
For historical web-compatibility reasons, the namespace object for console must have asits [[Prototype]] an empty object, created as if by ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%.
A group is an implementation-specific, potentially-interactive viewfor output produced by calls to Printer, with one further level of indentationthan its parent. Each console namespace object has an associated group stack, whichis a stack, initially empty. Only the last group in a group stack will hostoutput produced by calls to Printer.
The logger operation accepts a log level and a list of other arguments. Its main output is theimplementation-defined side effect of printing the result to the console. This specificationdescribes how it processes format specifiers while doing so.
If the console is not open when the printer operation is called, implementations should buffermessages to show them in the future up to an implementation-chosen limit (typically on the order ofat least 100).
Each console function uses a unique value for the logLevel parameter when callingPrinter, allowing implementations to customize each printed message depending on the function fromwhich it originated. However, it is common practice to group together certain functions and treattheir output similarly, in four broad categories. This table summarizes these common groupings:
The $$(selector) console utility function is "Query selector all". This DOM query selector function returns an array of all the elements that match the specified CSS selector, like the JavaScript function document.querySelectorAll(). In this example, we select all the hyperlink elements and then apply a green box around them:
The console is an operating system window where users interact with the operating system or with a text-based console application by entering text input through the computer keyboard, and by reading text output from the computer terminal. For example, in the Windows operating system, the console is called the Command Prompt window and accepts MS-DOS commands. The Console class provides basic support for applications that read characters from, and write characters to, the console.
When a console application starts, the operating system automatically associates three I/O streams with the console: standard input stream, standard output stream, and standard error output stream. Your application can read user input from the standard input stream; write normal data to the standard output stream; and write error data to the standard error output stream. These streams are presented to your application as the values of the Console.In, Console.Out, and Console.Error properties.
By default, the value of the In property is a System.IO.TextReader object that represents the keyboard, and the values of the Out and Error properties are System.IO.TextWriter objects that represent a console window. However, you can set these properties to streams that do not represent the console window or keyboard; for example, you can set these properties to streams that represent files. To redirect the standard input, standard output, or standard error stream, call the Console.SetIn, Console.SetOut, or Console.SetError method, respectively. I/O operations that use these streams are synchronized, which means that multiple threads can read from, or write to, the streams. This means that methods that are ordinarily asynchronous, such as TextReader.ReadLineAsync, execute synchronously if the object represents a console stream.
356178063d