What is “?:” notation in JavaScript?

后端 未结 4 2032
北恋
北恋 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条回答
  •  情话喂你
    2020-11-30 10:59

    Just read it like this:

    result = (condition) ? (true value) : (false value);
    

    place what ever you like in the 3 operators.

    As many has compared it to an IF.. THEN structure, so it is.

提交回复
热议问题