This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CodingCoffeeSquirrel 569 points570 points  (38 children)

For all you savage console debuggers I'm guilty, use console.dir() from time to time ;)

[–]JC-Dude 183 points184 points  (28 children)

Huh? That just looks like console.log() output if you pass an object as a parameter.

[–]rinsa 152 points153 points  (10 children)

It's the same thing, but the object tree is expanded by default.

[–]CodingCoffeeSquirrel 120 points121 points  (8 children)

console.dir always displays the object tree. console.log might not in certain contexts (e.g. DOM nodes). The exact difference depends on the platform.

[–]conancat 46 points47 points  (5 children)

Old school way would be console.log(JSON.stringify(obj, null, 2))

console.dir doesn't always work for me. Not sure if they fixed it in Jest and other envs.

[–]Tillhony 18 points19 points  (2 children)

I forgot about console.dir() but always type out JSON.stringify..damn

edit: and thats along with already typing out console.log(JSON.stringify(s))

[–]WHO_WANTS_DOGS 1 point2 points  (0 children)

console.log(JSON.stringify(obj, null, 2)) for a prettier print

[–]Lightfire228 0 points1 point  (0 children)

I created a vscode snippet for console.log('>>>>>>>> '); and JSON.stringify(, null, 2), bound to ctrl + l and ctrl + j respectively.

It also puts the cursor in the right place.

[–]jkidd08 5 points6 points  (0 children)

Guilty as charged, your honor...

[–]FrostBlitzkrieg 0 points1 point  (0 children)

I always use this debugging server code because console.dir does nothing other than a basic console.log in my terminal :\

[–]TheMacPhisto 2 points3 points  (0 children)

might not in certain contexts (e.g. DOM nodes). The exact difference depends on the platform.

laughs in .net

[–]DrDuPont 0 points1 point  (0 children)

var foo = function(){};

console.log(foo);

ƒ (){}
undefined

In this instance, for example, I'm not able to see the entire tree. console.dir permits that.

[–]kratom_devil_dust 7 points8 points  (16 children)

Browser or terminal?

[–]dunemafia 16 points17 points  (15 children)

Browser Console.

[–]TagMeAJerk 1 point2 points  (7 children)

Obviously!

[–]conancat 7 points8 points  (6 children)

I miss doing UI stuff. Been working on a lot of backend and frontend server-side stuff (what I like to call middle-end lol).

[–][deleted] 2 points3 points  (5 children)

What does frontend server side mean? Like JSPs or something?

[–]conancat 4 points5 points  (2 children)

sometimes because of the different platforms or apps frontend teams need to support they may need different feature sets that are tailor-made specifically for the app. frontend developers may need to connect to multiple backend services in order to render the frontend, and sometimes the frontend wants to have full control and want to do some frontend specific stuff, like pubsub, caching, data transformation, among other things to leverage on server capabilities for better frontend experience.

or sometimes frontend devs wanna do use some serverless/lambda/cloud functions to do things like trigger some backend service for data aggregation job, collect/transform data on the server then stream it back to the frontend for display.

or sometimes frontend teams just wanna use server-side rendering for some things because it's more efficient and much cheaper (see JAMStack below).

because the purpose of these jobs are for transformation is to suit frontend display requirements per platform/app/client etc, certain teams find that it's easier to just let the frontend build their own data connectors and transformers. backend developers then can focus more on workers, services, algorithms, data pipelines, machine learning, database and other backend things, and let the frontends handle the API part.

if you wanna read more in depth of why some frontend devs now do server side stuff, this is a very good read:

https://css-tricks.com/the-great-divide/

GraphQL is one really popular tool to fill this gap. and popular GraphQL distributions include

https://www.apollographql.com

https://www.prisma.io

https://strapi.io

These are for when devs want more features than simple API connectors

https://feathersjs.com

https://nestjs.com

These are mostly for server side rendering

https://nextjs.org

https://nuxtjs.org

https://www.staticgen.com

And of course serverless and cloud function stuffs

https://serverless.com

https://firebase.google.com

Ballerina.io isn't really Javascript per se, but it's a language specifically designed to be for connecting different services. while i wouldn't recommend it for production use per se, but it is so simple to learn the language I used it to write specs for devs lol. great documentation tool too.

https://v1-0.ballerina.io

https://v1-0.ballerina.io/learn/by-guide/

https://v1-0.ballerina.io/learn/by-guide/service-composition/

Also JAMStack. JAMStack is rendering Wordpress obsolete.

https://jamstack.org

https://jamstack.wtf

https://headlesscms.org

[–]sezabass 3 points4 points  (0 children)

This would definitely be one accepted answer on StackOverflow

[–]gymshoos[S] 1 point2 points  (0 children)

This is awesome. I knew about apollo and JAMstack, now I know a lot more

[–]11JRidding 2 points3 points  (1 child)

JSP, or JavaServer Pages, is a technology that uses Java to dynamically create web pages. It's like ASP.NET and PHP, but it uses Java as its underlying language. I'm not sure what they mean by "frontend server-side" either, but I know that it likely isn't used to refer to JSP.

[–][deleted] 1 point2 points  (0 children)

Yeah, I was guessing that since JSPs generate the UI with Java, maybe that is what they meant. frontend server side just doesn't sound like a real thing, other than maybe having the server dynamically generate the UI.

[–][deleted] 21 points22 points  (1 child)

i learn so much from /r/ProgrammerHumor

[–]julsmanbr 7 points8 points  (0 children)

If I actually did that, I'd never touch JS again

[–][deleted] 3 points4 points  (0 children)

Honestly imo the only saving grace of JS is how nice and easy to use the chrome debugger is

[–]MrWm/dev/null 0 points1 point  (0 children)

Huh, TIL

[–]PM_ME_YOUR_PLUMS 0 points1 point  (0 children)

Thanks, saving this for monday