Can I omit the else in an inline javascript if statement?

后端 未结 7 1379
鱼传尺愫
鱼传尺愫 2021-02-07 02:50

I\'m trying to use this and it doesn\'t appear to be working. I\'m guessing it\'s just not an option, but want to confirm. Is this valid?

(if_it_is) ? thats_cool         


        
7条回答
  •  青春惊慌失措
    2021-02-07 03:06

    You miss the third component. Should be something like that:

    (if_it_is) ? thats_cool() : not_too_cool();
    

    The whole sense is:

    condition ? do_something_if_condition_is_true : do_something_if_condition_is_false;
    

提交回复
热议问题