以下內容是什麼意思?這是什麼意思?這是否是代表性?
var iCurrentIndex = oCurrentQuestionModel.getProperty("/index"); ...(1)
iCurrentIndex = iCurrentIndex ? ++iCurrentIndex : 0; ...(2)
的VAR iCurrentIndex =在SETP 1和第2步虛假它被分配值0。 這是什麼意思的表示任何人都可以解釋一下嗎?
以下內容是什麼意思?這是什麼意思?這是否是代表性?
var iCurrentIndex = oCurrentQuestionModel.getProperty("/index"); ...(1)
iCurrentIndex = iCurrentIndex ? ++iCurrentIndex : 0; ...(2)
的VAR iCurrentIndex =在SETP 1和第2步虛假它被分配值0。 這是什麼意思的表示任何人都可以解釋一下嗎?
假設
var iCurrentIndex = oCurrentQuestionModel.getProperty("/index");
返回undefined
或null
或只是false
,那麼增量不能成行。
然後,您需要檢查返回的值是否爲truthy(如果轉換爲布爾值,則該值將解析爲true
),然後將值增加或指定爲iCurrentIndex
。
iCurrentIndex = iCurrentIndex ? ++iCurrentIndex : 0;
上面conditional oparator使用條件和?
後評估任一部件,if
語句的然後部分或:
之後的部分,一個if
語句的else
一部分。
謝謝。那麼三元運算符是否更傾向於if語句? – loki
@loki,實際上,你做了一個增量**和**一個賦值,所以它不是一個真正的使用條件運算符的好例子。 –
這是一個三元組:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator –
@Jeremy Jackson謝謝。 – loki