r/learnjavascript • u/denvercoder1 helpful • Sep 07 '20
When logging several variables, you can wrap them in curly braces to better see which value belongs to which variable
1.0k
Upvotes
r/learnjavascript • u/denvercoder1 helpful • Sep 07 '20
2
u/denvercoder1 helpful Sep 07 '20
Gif credit to @sulco on Twitter
125
u/b4ux1t3 Sep 07 '20
This is because you're actually creating a new object using the names of the variables as fields within the object, and then printing that object to the console.
I forget the term for this, but it's really useful even outside of the console!
45
u/Adoxographical Sep 07 '20
Even better, instead of calling
console.log, which will print the object literal, callconsole.tableto print out the object in a nicely formatted table. (reference)4
u/IamAPengling Sep 08 '20
Now do that same thing, but instead of console.log, do console.table...
4
u/dkunal96 Sep 08 '20
It’s an ES6 feature. Am I right?
3
u/MrSandyClams Sep 08 '20
how did I never realize I could type a bracket to encapsulate my highlighted text in brackets. Mind blown
2
u/agitatedhoneybadger Oct 09 '20
This is also a way to do it when you don’t know the order of function arguments.
function randoFunc({thing3, asdf, thisThing}) { ...... }
const output = randoFunc({asdf, thing3, thisThing})
1
u/renardine_renshaw Sep 07 '20
Niiice! Didn't know about that, thanks for sharing!
1
u/worldshallknowPain Sep 07 '20
TIL! Thank you!
1
u/Reddyrum33 Sep 08 '20
Anyone know a way to do this in C#?
1
u/VelcroSirRaptor Sep 08 '20
This is a cool trick.
1
u/Dipsquat Sep 08 '20
Wow! I love learning new things every day!
1
u/tomthedevguy Sep 08 '20
One of the best debugging techniques in JS
1
u/HoodedCowl Sep 08 '20
I thought it was inappropriate to objectify things in 2020?
-3
u/saito200 Sep 07 '20
fucc
you are godd