Question mark and colon in statement. What does it mean?

后端 未结 7 1313
南方客
南方客 2020-11-27 14:03

What do the question mark (?) and colon (:) mean?

((OperationURL[1] == "GET") ? GetRequestSignature() : "")
         


        
7条回答
  •  有刺的猬
    2020-11-27 14:40

    In the particular case you've provided, it's a conditional assignment. The part before the question mark (?) is a boolean condition, and the parts either side of the colon (:) are the values to assign based on the result of the condition (left side of the colon is the value for true, right side is the value for false).

提交回复
热议问题