Benefits of using the conditional ?: (ternary) operator

后端 未结 17 1028
孤街浪徒
孤街浪徒 2020-11-22 06:55

What are the benefits and drawbacks of the ?: operator as opposed to the standard if-else statement. The obvious ones being:

Conditional ?: Operator

17条回答
  •  灰色年华
    2020-11-22 07:34

    I find it particularly helpful when doing web development if I want to set a variable to a value sent in the request if it is defined or to some default value if it is not.

提交回复
热议问题