Which is clearer form: if(!value) or if(flag == value)?

后端 未结 19 2706
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 19:07

I understand this is a subjective question, so I apologize if it needs to be closed, but I feel like it comes up often enough for me to wonder if there is a general preferen

19条回答
  •  既然无缘
    2020-12-23 19:45

    I actually many of forms possible.

    This is not actually how it is written to standards, but this is how I see it:

    //if foo is(or exists)
    if(foo)
    
    //if foo is true
    if(foo == true)
    
    //if foo doesn’t exist
    if(!foo)
    
    if foo is false
    if(foo == false)
    

    Hence I don’t see == false is redundant.

提交回复
热议问题