Printing in the console is pretty easy all we have to know is how to activate the console on the chrome for viewing. The Console is always active all we are doing is making it visible to the front-end. A console is an object which provides access to the browser’s debugging console. Console object has many methods which help us to print customized debugging.
Here, are the following methods:
- assert(): Acts like ‘if’, prints to console if false.
- clear(): Clears the console.
- count(): counts whenever it gets called.
- error(): prints error if any.
- group(): Creates a new inline group in the console.
- groupCollapsed(): Creates a new inline collapsed group in the console.
- groupEnd(): Exits the inline group in the console.
- info(): acts just as log, for priority info.
- log(): Outputs a message to the console.
- table(): Displays tabular data as a table.
- time(): tracks how long the specific task taking place.
- timeEnd(): ends the tracker.
- trace(): Outputs a stack trace.
- warn(): Outputs a warning message.
Click on F12 after running the script and it opens the Developer Tools, navigate to the Console tab, which will be on the top menu.
After clicking the button:
Example 2: Check out the console.table() for better understanding of methods.
After Clicking the button: