News for hackers. Stuff that matters.
Re:Console.table() by nicusor on Thursday June 14, 2018 @03:32AM (#17310021)
Another useful trick I've been using for some time is

console.log({ a, b })

where a and b are some variables. This will print the name of the variable next to its value. So it can be thought as a faster version of

console.log('a: ' + a)

Re:Console.table() by jayrhynas on Thursday June 14, 2018 @09:06AM (#17311334)
That's due to a shorthand added in ES2015 that lets you construct an object where keys are equal to the name of the variable. So that's short for

    console.log({ a: a, b: b })
and then the console just prints out the new object.
Re:Console.table() by Raphmedia on Thursday June 14, 2018 @10:08AM (#17311750)
Nice trick.

What I do is console.log('MyVariable',MyVariable,'MyOtherVariable',MyOtherVariable);

When writing it I simply copy the variable, "paste twice" and then "wrap with quotation marks".

That one is pretty nice because you can add ,'\n' to have a new line. console.log('MyVariable',MyVariable,'\n','MyOtherVariable',MyOtherVariable);

Re:Console.table() by foreigner on Thursday June 14, 2018 @03:53AM (#17310113)
Nice! Thank you
Re:Console.table() by anonytrary on Thursday June 14, 2018 @04:02AM (#17310153)
Completely tangential, but you can also do the opposite with nesting, which I learned about literally yesterday:

const { some: { nested: { field } } } = tree; // field === tree.some.nested.field

or rename things while you destructure them:

const { crappyFieldName: betterName } = myObject; // betterName === myObject.crappyFieldName

Now I can't stop using this feature...