What is “?:” notation in JavaScript?

后端 未结 4 2033
北恋
北恋 2020-11-30 10:19

I found this snippet of code in my travels in researching JSON:

var array = typeof objArray != \'object\' ? JSON.parse(objArray) : objArray;
<
4条回答
  •  旧时难觅i
    2020-11-30 10:35

    That’s called the conditional operator:

    condition ? expr1 : expr2
    

    If condition is true, the operator returns the value of expr1; otherwise, it returns the value of expr2.

提交回复
热议问题