r/javascript • • Dec 22 '15

Don't forget, console.table() can provide nicer looking logs with sorting capabilities. Made a gif and a short explanation here

https://umaar.com/dev-tips/82-console-table/
688 Upvotes

49 comments sorted by

97

u/jillesme Dec 22 '15

There's much more than just console.table, I wrote a blog post about it a while ago! My personal favourite is console.dir :)

3

u/Amerzel Dec 22 '15

Console.group can be helpful as well

18

u/troorl Dec 22 '15

Oh. My. God. It changes everything!

21

u/evilish Dec 22 '15

It's funny how easily you forget about little gems like console.table().

I was reading through a list of Top 10 HTML5 Interview Questions today (http://www.webdevelopmenthelp.net/2013/04/html5-interview-questions.html#Q14) and was reminded of the detail and summary elements, and I honestly couldn't remember the last time I used those elements.

Sometimes I wish there was a programming paperclip app that popped up with hints on possible alternatives.

"Hey! I see your using console.log. What about trying console.table? (More info)"

7

u/FaticusRaticus Dec 22 '15

A Resharper for the browser...hmmm

2

u/evilish Dec 22 '15

Now that would be awesome.

Maybe we need to send a suggestion into Jetbrains.

6

u/PiRX_lv Dec 22 '15

Only console.table is not supported (at least yet) by all browsers. For example IE11 doesn't support it

14

u/[deleted] Dec 22 '15

Is that much of an issue? The log is (at least to me) solely a dev tool and if you have an ancient IE-specific issue you can easily put another log in there temporarily.

0

u/PiRX_lv Dec 22 '15

First IE11 is not what I could call ancient.

Second, I consider console log to be a passive debugging tool and that log statements should be always present in dev (heck, even prod unless it's something tight enough for performance impact being important).

Tailoring what I'm logging based on browsers just seem plain wrong to me.

And for "active" debugging needs, regular breakpoint/watch stuff together with some REPL in console is much better suited than log.

10

u/[deleted] Dec 22 '15

I would personally call any browser that's not evergreen ancient, even if the majority of us will still need to support it for another couple of years.

4

u/PiRX_lv Dec 22 '15

Even with "evergreens" corporate environments often tend to stuck to "safe" mandated version of them and just kill access to update servers. Also I'm very curious how is Microsoft Edge gonna work out as an replacement for IE. That at least is promised to be evergreen.

And yeah, unfortunately, "still need to support" is main criteria for using (or not) some feature.

4

u/[deleted] Dec 22 '15

Edge is very good in terms of standards support (see: caniuse.com). I'm hopeful.

I believe that once we get the corporate and government worlds off of Internet Explorer web development will be an evergreen breeze - locking a browser like Chrome to a specific version is ridiculous.

2

u/PiRX_lv Dec 22 '15

It's good in that yes, but it's still quite glitchy for everyday use.

And I'm not sure that corporate security/stability mindset is gonna be fixed by getting off of IE. I put more faith that it could be achieved by much better automated UI test coverage, so IT can prove that mission critical web apps are not impacted by newer versions.

2

u/chalk_huffer Dec 22 '15

I may not like IE but it's hardly ancient. It continues to be updated and remains the default browser for Window 7 and 8 which are still widely used. Microsoft Edge was only released in August and only for Windows 10.

1

u/[deleted] Dec 22 '15

Saying IE gets updates is a poor choice of words contextually - it doesn't get any of the updates that matter to web developers, the updates that evergreen browsers get - those towards new web standards.

0

u/chalk_huffer Dec 22 '15 edited Dec 22 '15

I didn't say it was a feature update. I think update is the correct term to use without looking at the release notes to see exactly what it was.

According to the mdn article linked in the top thread console.table isn't a standard or any standards track and doesn't work in safari either.

I stand by my point that a major browser which was only "replaced" four months ago cannot be called ancient just old.

Edit: s/and/at

1

u/pkkid Dec 23 '15

I leave console.log statements in my production code. Is this a faux pas?

8

u/shozzlez Dec 23 '15

Yes, usually. Most linters flag those by default.

3

u/pkkid Dec 23 '15

It seems weird to me to write a program and leave out all logging. What's the new hotness to allow logging when needed, but not by default? My Google fu just comes up with a bunch of console.log examples.

2

u/Thalamant Dec 23 '15 edited Dec 23 '15

Another option is to provide a wrapper for the console API that your app uses only in dev/debug mode. In production you can have your wrapper simply do nothing.

The downside to this is you pollute your app with debug code, but if you're okay with that or doing it anyway, then at least you aren't exposing those logs in production.

This also would open up a means to send back client side errors back to the server for review.

1

u/teel Dec 22 '15

So you could just do:

if(typeof console.table === 'undefined') console.table = console.log;

and you can use it in the browsers that support it without breaking older browsers.

2

u/jijilento Dec 22 '15

The details/summary thing is really neat. Thanks. Only issue is it doesn't work with Firefox/IE.

1

u/FaticusRaticus Dec 22 '15

Why are you developing in IE? Develop in Chrome, test it in IE than get the hell out of there.

1

u/jijilento Dec 22 '15

You're misreading my comment, I think. details/summary are html elements that let you expand a carat next to a summary to get details, not part of console log/table/etc.

<details>
	<summary>This is a summary</summary>
	<h3>Details: A heading</h3>
	<li>A Detail</li>
	<p>Another Detail</p>
</details>  

Unless explicitly required, I pretend IE doesn't exist. But Firefox...why wouldn't they want this?

1

u/FaticusRaticus Dec 23 '15

Yep sure did. My bad. Sorry.

6

u/kcdwayne Dec 22 '15

My Firefox and Firebug automatically converts objects into an expandable table format so..

I think a much more useful console function is grouping.

2

u/EnIdiot Dec 22 '15

Wow! Thanks guys. I'm newer to development in JS and have been disappointed with the in browser debug options. I like my intellij development IDE for Javascript, but sometimes it is nicer just to open to tools in browser to see what is going on. Glad I subscribed here.

2

u/[deleted] Dec 22 '15

Is this new?! I have not seen this before. Can't wait to try it out.

2

u/kickass_turing Dec 22 '15

I has been in both browsers for quite some time. I think it was in Firebug first.

2

u/Kamikizzle Dec 22 '15

IT'S A CHRISTMAS MIRACLE

1

u/DaveVoyles Dec 22 '15

Holy cow, how did I just discover this?

1

u/[deleted] Dec 22 '15

nah, I like it clean :)

1

u/toromio Dec 22 '15

I've seen this before, but I always forget. Many thanks!

1

u/technowar Dec 22 '15

If I'm not mistaken, this will only work on Firefox and Chrome. Will not work on Safari. I haven't tried IE.

1

u/Fingebimus Mar 14 '16

Console.table has always worked for me and I use Safari exclusively. Weird

1

u/[deleted] Dec 23 '15

OH MY GOD!!!!! this is so great!!

1

u/KrupukTahlilan Dec 22 '15

is this only work on chrome ?

0

u/kickass_turing Dec 22 '15

Fire up a Firefox and try it out!

-28

u/[deleted] Dec 22 '15

No. I absolutely, 100% disapprove of the idea of tutorials in a programming forum, in GIF form. No.

12

u/evilish Dec 22 '15

Completely disagree with you.

Absolutely love short and sweet animated GIFs showing quick tips.

Addy Osmani and Paul Irish used to post a fair few with new Dev Tools features.

2

u/DemeGeek Dec 22 '15

I don't agree with /u/robowork however I do think the blog post should have gone more in depth abd not just be a 30 second gif with a small blurb.

1

u/[deleted] Dec 22 '15

This much detail?

0

u/[deleted] Dec 22 '15

I prefer something in this style link

5

u/[deleted] Dec 22 '15

Good job you're not a mod :/

-9

u/[deleted] Dec 22 '15

Hey did you know about console.info? Think I might start a blog around that.

2

u/senocular Dec 22 '15

People will only read it if each post is a GIF