It's sometimes hard to debug with many logs at the same time.

Let's take an example:

function min(a, b) {
 return Math.min(a, b);

min(1, 0); // 0
min(14, 5); // 5

Solution 1

In order to clearly identify the variable, we could write this:

console.log('b: ', b);


b: 0
b: 5

Solution 2

We could also use this syntax:

console.log({ b });

Result :

{ b: 0 }
{ b: 5 }

By using curly brackets, we create an object. We use here an ES6 syntax: if the variable and the object property have the same name, it becomes unnecessary to repeat the information.

For instance:

const firstName = 'John';
const user = {
	firstName: firstName,

Can be shortened as follow:

const firstName = 'John';
const user = {

To sum up, when we log a variable like: console.log({ myVariable }), we use the object property shortand syntax, and the variable is logged as an object.