Console Tricks
Credit : Unknown

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):

No alt text provided for this image

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 ()

No alt text provided for this image


This will output the fruits variable in the basic console.log


Styling

We can style the console in various ways. Examples

No alt text provided for this image
No alt text provided for this image

or even combine the styles

No alt text provided for this image

This is the list of CSS format specifiers that we can change in the console

No alt text provided for this image


console.dir ()

No alt text provided for this image

You can even dir the Documents. It will return as an object

No alt text provided for this image



console.count()

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image


console.count will do the incremental for us instead of counting manually. This is convenient


console.table()

No alt text provided for this image


console.table() will print a visual table representation of an object with rows for each of the object properties


console.assert()

No alt text provided for this image


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()

No alt text provided for this image
No alt text provided for this image

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

No alt text provided for this image

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()

No alt text provided for this image


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


Jeff Loo

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 ??

Joey Law, CQMgr,CSMgr,CSM,CSPO,CSQA,CSQE,CSTE

?????? 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

Joseph Irving D'aranjo

| Commercial and Business Development | Sustainability Advocate | Interior Designing | Hospitality | Project Management |

3 年

Appreciate the sharing Ivan Always learning from you.

Hing-Nan CHENG

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. ????

要查看或添加评论,请登录

Ivan T.的更多文章

  • Short hiatus (1 month) from social media and its impact

    Short hiatus (1 month) from social media and its impact

    I am a huge fan of LinkedIn, Instagram, TikTok, YouTube, Reddit, a few e-commerce sites and other popular platforms. I…

    15 条评论
  • Solution Focused - Not Knowing Position

    Solution Focused - Not Knowing Position

    Solution Focused Brief Therapy (SFBT) is a form of therapy that has gained popularity in recent decades. It is a brief…

    9 条评论
  • Text Counselling

    Text Counselling

    Why is counselling important for our mental health Counselling is important for mental wellness because it provides a…

    13 条评论
  • Loneliness

    Loneliness

    We feel lonely from time to time. The feelings of loneliness are personal, and everyone's experience will differ.

    9 条评论
  • Struggling over popular festive season (Lunar New Year)

    Struggling over popular festive season (Lunar New Year)

    Lunar New Year is this week. It is meant to be a time of joy with celebrations, red envelopes, gifts and qualify family…

    9 条评论
  • Passing data in React between Parent and Child in Functional Components

    Passing data in React between Parent and Child in Functional Components

    For beginners who started out in ReactJS, passing data between components may be confusing. I struggle this when I…

    6 条评论
  • Getting your React project ready for?Heroku

    Getting your React project ready for?Heroku

    If you are new to React JS and want to deploy to Heroku, these are few steps to ensure that you can deploy…

    3 条评论
  • Why And How We Should Learn To Say?No

    Why And How We Should Learn To Say?No

    Are you a people pleaser ? Do you find it difficult to say "No" or reject an invitation, task or someone's request ?…

    9 条评论
  • HTTP Status Code

    HTTP Status Code

    When we visit a (web) site, it usually send some request to the server. There will be a returned code to indicate the…

    24 条评论
  • The Power of Stepping Away

    The Power of Stepping Away

    We have been there. Whether it is moving to a new department or in a unfamiliar role, we have encounter problems that…

    27 条评论

社区洞察

其他会员也浏览了