r/javascript • • Mar 18 '19

What's your favorite, most useful javascript one-liner?

385 Upvotes

422 comments sorted by

View all comments

19

u/drboyfriend Mar 19 '19

console.table(obj1); and console.log(JSON.stringify(obj1, null, 2); for debugging.

3

u/thisguyfightsyourmom Mar 19 '19

I use console.log(JSON.stringify(yo, null, 2) when I need to copy paste objects out of the console—super quick way to get a pile of placeholder data

14

u/Oririner Mar 19 '19

just copy(yo) ;)

(in Chrome DevTools)

2

u/thisguyfightsyourmom Mar 19 '19

You’re telling me I’ve learned what the second arg in console.log for nothing?!

It’s nice for inspecting objects (readably) in test suites too—quick,… someone tell me the smarter way to do that too

2

u/Oririner Mar 19 '19

It sounds like you're not debugging the test suites in Chrome DevTools.

you should do that instead ;) just add --inspect-brk when running the node process and follow the instructions.

→ More replies (1)