DEV Community

Discussion on: JavaScript pro programmer vs newbie programmer

Collapse
 
miketalbot profile image
Mike Talbot ⭐ • Edited

Another one of those "pro-dev" things that can be a bit confusing is this for only positive conditionals:

     condition && console.log("Was here")

I can never make my mind up if I like it - I do write that when debugging, but pretty much never in "real code"

It works with everything apart from assignment which requires brackets

condition1 && condition2 && (something = somethingElse)

Again not advocating, but it is out there in people's code.

Thank goodness of optional chaining though (thanks babel) so my if's can go from:

   if(someObject && someObject.subObject&& someObject.subObject.value > 299) {
     //whatever
   }

to

   if(someObject?.subObject?.value > 299) {
   }