If without else ternary operator

前端 未结 10 676
太阳男子
太阳男子 2020-12-05 17:04

So far from I have been searching through the net, the statement always have if and else condition such as a ? b : c. I would like to know whether the if<

10条回答
  •  离开以前
    2020-12-05 17:21

    Yes you can do that actually (in JavaScript at least):

    condition && x = true;
    

    or (in JavaScript, and there might be a similar way to do this in Java):

    void(condition && x = true)
    

提交回复
热议问题