I am currently available for freelance/contract work. Book a meeting so we can talk about your project.

Logging as objects

Posted on

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.
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.
Debug
none
Grid overlay