DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Sanchithasr
Sanchithasr

Posted on

JavaScript Console commands other than console.log()

Tired of using console.log() for everything while debugging your code? We often print the messages in browser console to debug the wired problems in our codes. But why use only console.log() when we have lot of other commands as well which could make our lives easier.
So here are few console commands we could make use to make our debugging process lot easier.


1. console.error() β€”

Sends message to the console window. The message text is red and prefaced by an error symbol.

Alt text of image

2. console.warn() β€”

ends message to the console window, prefaced by a warning symbol.

Alt text of image

3. console.table()β€Šβ€”β€Š

Displays the JSON / Array in table format which is easier to read.

Alt text of image

4. console.group() and console.groupEnd() β€”

console.group() and console.groupEnd() are used to group the messages.

Alt text of image

NOTE: The console.groupCollapsed( ) can be used instead of console.group() to make it appear in a collapsed view by default.

5. console.dir() β€”

It displays the JSON in an object visualizer. Makes it easier to inspect properties in the console window.
Alt text of image

6. console.assert(expression, message)β€”

Sends a message to the console window if expression evaluates to false.
Alt text of image

7. console.time(β€˜name’) and console.timeEnd(β€˜name’)β€Šβ€”β€Š

These are used to track time of the codes between them to get executed. It calculates the time that elapses between time and timeEnd, and sends the result (measured in ms) to the console using the name string as a prefix.
Alt text of image

8. console.clear()β€Šβ€”β€Š

This command is used to clear the console messages. Just run this command and your console will be clear as new.

And that sums it up..

Thank you

Top comments (6)

Collapse
 
habeebullahi01 profile image
Habeebullahi01

I always thought of the other things that could come after "console.", but I never bothered googling it. Console.thanks(author).πŸ€—πŸ˜

Collapse
 
sanchithasr profile image
Sanchithasr Author

Haha. Glad you found the blog helpful 😊Thank you for reading.

Collapse
 
shwetabh1 profile image
Shwetabh Shekhar

Loved the post. Clear and concise.

Collapse
 
sanchithasr profile image
Sanchithasr Author

Thank youπŸ‘

Collapse
 
anicode profile image
Abhis

I guess you forgot to add these as well:

dev.to/prodexia/ultimate-css-class...

Collapse
 
sanchithasr profile image
Sanchithasr Author • Edited on

This post is about pseudo classes. I didn't find any console commands. Did I miss anything?

Visualizing Promises and Async/Await 🀯

async await

☝️ Check out this all-time classic DEV post