Console Tricks
Console is is a favourite feature for many web developers. If you have been using it, you know there are lots of tricks. Here are some that I like to share.
First a disclaimer :
I do not discover this knowledge by myself. I read them from several sites / sources. This article collect the data from several sources , and while I was learning and rediscovering from what I have already known, I decided to compile them and re-share them according to my understanding.
If you enter console in your browser, you will see this (below):
As you can see in the image, console has lots to offer beside a mere console.log. I am going to introduce some of the functionalities that may be useful to you.
Basic console.log ()
This will output the fruits variable in the basic console.log
Styling
We can style the console in various ways. Examples
or even combine the styles
This is the list of CSS format specifiers that we can change in the console
console.dir ()
You can even dir the Documents. It will return as an object
console.count()
领英推荐
console.count will do the incremental for us instead of counting manually. This is convenient
console.table()
console.table() will print a visual table representation of an object with rows for each of the object properties
console.assert()
console.assert() will help us to decide if the condition passed or failed. In the above line, there is no "grapes" in the object fruits, hence console assert as failed
console.trace()
From the above code, trace helps to print the stack trace of the code. Call the function and you will see the exact trace message that the code was called in.
console.time / console.timeLog / console.timeEnd
console.time() start a timer. console.timeLog() print the time since the timer has started. Lastly console.timeEnd() print the total amount of time.
console.group() / console.groupEnd() / console.groupCollapsed()
This is useful to group message that will arrange in a group rather than in a mess. When you use console.groupCollapsed(), the group will collapse by default
Driving Sustainable Innovation | Green Finance | ex-Sembcorp | Carbon Accounting | Lecturer, Mentor | Digital Transformation | Seeking Impactful Opportunities in Sustainability
3 年Definitely useful to know and learn. Thanks for sharing. Ivan T.
Thanks for the sharing ?? Ivan T. It will come very handy ??
?????? Inventing transformative, innovative, game-changing, show-stopping, industry-disrupting, Why-Didn't-I-Think-Of-That mouse traps benefitting the entire global population. ??????
3 年Thank you Ivan for sharing
| Commercial and Business Development | Sustainability Advocate | Interior Designing | Hospitality | Project Management |
3 年Appreciate the sharing Ivan Always learning from you.
Expert in Job Win | Personalized Job Search Strategy | Deep Dive Approach | Comprehensive Business Network | ACCDF | ACLP | Certified Career Practitioner
3 年Thank you for sharing your professional knowledge Ivan T. ????