How to use Computed Property Names in console.log?

Search for a command to run...

No comments yet. Be the first to comment.
Last week, I encountered issues with my existing Ubuntu setup. It was slow and lagging, and I couldn't resolve the problem. Then, I remembered that my laptop had two operating systems installed: Windows and Linux on separate partitions. Suspecting a ...
Hello artisans, Today I'll be writing about how to use Query Scopes efficiently in Laravel projects. Query Scopes are very useful to encapsulate the logic you want to apply to database queries while using Models. Let's start with an example and under...

Laravel Sanctum is one way to authenticate different models to use your application but there are many other ways. In this article, I'll be explain how to authenticate team/team members with a Laravel Sanctum. Assume that we have following Model; cla...
Introduction: Managing forms in web applications can be a complex task, especially when dealing with validation rules, error handling, and form submissions. The React useForm plugin library offers a powerful and elegant solution to simplify form mana...

If you want to learn about how to use console.log as a professional developer then you have to learn computer property names.
Assume that we have 4 different objects and each one is assigned to a variable. How can we log those objects to see what are they?
const obj1 = {name: 'Joe', age: 21, happy: true}
const obj2 = {name: 'Jane', age: 20, happy: true}
const obj3 = {name: 'Jona', age: 1, happy: false}
const obj4 = {name: 'Jake', age: 2, happy: true}
Of course, the first thing that comes into mind is to use pretty console.log :)
console.log(obj1);
console.log(obj2);
console.log(obj3);
console.log(obj4);
Result;

As you can see we could log all variables. If I ask you which of those logs represents a variable named obj2 can you tell me that without looking and remembering the code? Of course not! Because you don't know that.
But hey look there is a better way called Computed Property Names and basically, we put all those variables into an object in console.log like as below;
console.log({obj1, obj2, obj3, obj4})
As a result, we have 1 line of code and 1 log that represents the whole data as below.

If I ask you the same question again Which one of those data represents the variable named obj2?
Then you tell me the object which has a name attribute as Jane is the obj2 without requiring to check the code.