vendredi 18 juin 2021

if statement with javascript condition operator

just have 2 question regarding JS conditional operator, is the below 2 expression valid?

1.

if(isUser && isUser === true || isGuest && isGuest === true){
     //...
   }

I am wondering do I have to add () to make it like and still have the same functioning:

if((isUser && isUser === true) || (isGuest && isGuest === true)){
     //...
   }
    const items = list.orderList && list.orderList.isUser === true || list.orderList.isGuest ? list.items : [];
    

    I am wondering do I have to add () to make it like and functioning the same as above conditional operator:

    const items = list.orderList && (list.orderList.isUser === true || list.orderList.isGuest === true) ? list.items : [];
    

    Aucun commentaire:

    Enregistrer un commentaire