- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
Explain all Console Object in HTML
The console is available in every scope since it is a global variable. In the browser window, it can be used as the ‘window.console’ or simply ‘console’ will work and in the browser window, it is present in the global scope.
There are various console object methods, let's see each of them one by one −
If the assertion is false then this method will show a message otherwise no message will be displayed there in the console. Let’s see its syntax first and then move to its code −
In the above syntax, we can see there are two parameters passed to the assert function, one is the expression and another is the message.
Expression is the expression that will be checked for the assertion of the message to the console. If the output of the expression is false then the message will be displayed on the console otherwise nothing will happen.
The message is the message that the user wants to display on the console.
Due to the many messages present in the console, it may become cumbersome, to remove all the messages from the console we can use the clear() method which works exactly as its name. Let’s see its syntax.
After the above expression will be encountered the console will be cleared and there may or may not be a message that appears to indicate that the console is cleared. Google shows this message while in Firefox no returned message will be generated.
Here, the label is the message that will be printed in the console, also if the user doesn’t send any label then by default “default” will be printed as the message.
As the name suggests the error() method prints the error on the console which is nothing but a message which can be printed on the console for the purpose of testing a program, but the best part of the error method makes it better as compared to other methods is it prints the message in the red color.
Here, the message is an error message which is provided by the user and printed in red color on the console.
group() Method is used to create a new inline group in the console. As all the console messages appear in levels, it provides an extra or additional level and all the new messages appear in that same level until the groupEnd() method is called. Let’s see the syntax of the group() Method −
In the above syntax, label is the message which is not necessary or more specifically the compulsory parameter to pass.
groupEnd() Method of the console is nothing but the method to end the group created using the group() method. Using group() method we can start a new inline group and to close that group we can use the groupEnd() Method. Let’s set its syntax −
There is no parameter passed to this method, hence nothing will be printed on the console.
To give any special information on the console the info() method is used. On some browsers there may be any special icon appears in front of the message printed using the info() method, like in the firefox browser a small ‘i’ icon will be present. Although, on many browsers it may not present and a simple message is present instead. Let’s see its syntax −
Here message is the special message that user wants to print in the console as the information and by using the info() method, user may give some extra information through the code and make code more readable.
In the above syntax, the message could be a string, array, object, etc. log() method is mainly used for the testing purpose mostly.
As per the name, table method of the console is used to print the data in the table format in the console. This makes the data look clear on the console and to present the data in the specific manner so it becomes more readable. Let’s see its syntax −
In the above syntax, we have passed two parameters, first parameter ‘tabledata’ is compulsory and contains the data to present and second parameter is optional and if not given then the column names are taken by default starting from zero.
time() method is used to start a timer to get the idea how long a testing process lasts. It will start a timing in the console and can be seen there. Let’s see its syntax −
In the above syntax, label is the name given to the timer, so we can get unique type of timers in the console.
To end a timer we can use the timeEnd() method and it will end the timer. Let’s see its syntax −
In the above syntax, label is the name of the timer which is initially started and now user wants to stop.
- Related Articles
- Explain Storage Object in HTML
- How do i Make JS Console Output As Text In HTML?
- How to print to console an object in a MongoDB script?
- Display all the titles of JTabbedPane tabs on Console in Java
- HTML DOM HTML Object
- HTML DOM Object Object
- Explain BLOB object and tree object in Git.
- Explain HTML formatting in PowerShell?
- Select all elements with “data-” attribute with jQuery and display on Console?
- Explain narrowing with object in Java.
- Console Class in C#
- HTML DOM Ins Object