As a Javascript beginner, console.log() is the favorite code statement of developers. And why not? console.log() is the G.O.A.T. when it comes to debugging the JS code. It's a versatile tool, allowing you to inspect and understand the flow of your code tracking program execution. But while console.log() enjoys the limelight, we should not forget that there is more to it. Allow me to introduce its behind-the-scenes cool helpers –
\> console.assert(): Think of it like a code bouncer— it only logs an issue if something's off. In some cases, you only want to log something if the condition is false. When the first argument is false, it logs the second argument as an error.
\>console.table(): Ever wish your arrays looked more like tables? Boom, problem solved. Just pass an array in console.log(), and you are good to go.
\>console.group(): As js developers, we quite often abuse console, and that can make it pretty messy. Use console.group to group things together. then collapse them by default to save space. Keep your logs tidy with groups. Perfect for staying organized.
\>console.dir(): Think of it as a personal guide revealing the inner workings of complex objects. Things also get ugly when you're logging a bunch of objects. Change it to console.dir(), and you get a much cleaner triangle drop-down.
\>console.count(): Wanna know how many times a bit of code runs? Just use this counter. Ever find yourself manually incrementing numbers on your console? If so, you can save your sanity and use console.count(). It takes an optional label, and every time it is called, it will increment the count by one.
\>console.time(): Want to know how long your code takes? Start the clock! Calling console.time() will start the clock, and then. console.timelog() will log the amount of time you have lapsed since the code was started.
\>console.trace(): Wondering where you are in the code? Trace it out. In JS, we are often working in the context of deeply nested functions and objects. When debugging, it may be necessary to traverse through the stack trace of your code. Use .trace()
And lastly, every good JS developer should provide their console.log some flare. Use percent C as the first character of the string, then pass it some CSS styling as your second argument, and then the console is your canvas!!!!!!!!!!!!!!!🌈