DEV Community

Discussion on: Tips in Javascript

Collapse
 
codevault profile image
Sergiu Mureşan

This

   const nameAndEmails = users.map((user) => console.log(user) || ({ 
        name: user.name, 
        email: user.email
   }))

is neat. I have to admit.

The problem is, it's really hard to understand and few people know about this || syntax, let alone the return value of console.log. In production this type of code wouldn't even fly past code review.

So use it sparingly and with some comments for others to understand.

Collapse
 
azrizhaziq profile image
Azriz Jasni

Agreed, this code will not pass in code review. But essentially it just to make developer debugging easier.