Logging as objects

By wrapping the variables in a console.log in curly brackets, it logs an object that uses the names of the variables as keys. That makes it easier to see what each value represents.

const apples = 6
const children = 3
const cars = 1

console.log(apples, children, cars)
// ⇒ "6, 3, 1"
// Wait, what does the `3` mean again?

console.log({ apples, children, cars })
// ⇒ "{ apples: 6, children: 3, cars: 1 }"
// The variables’ names act as labels here.

There is more to learn

Get free previews of my upcoming course materials and other bonus content to help you work smarter. I share tips straight to your inbox once a week. You can read previous mails in the newsletter archive.

Cannot show form because cookie consent was not given.