0

can someone please explain the role of the ? in this function

function add() {
    h1.textContent = (hours ? (hours > 9 ? hours : "0" + hours) : "00") + ":" + (minutes ? (minutes > 9 ? minutes : "0" + minutes) : "00") + ":" + (seconds > 9 ? seconds : "0" + seconds);
}

I read that the ? works as follows varname = (condition) ? value1:value2. If the condition evaluates to true the variable becomes equal to value1 else value2.

Which I understand. But i'm getting confused by the nested ? in the above and how to parse it...

Mathlearner
  • 107
  • 5
  • https://stackoverflow.com/questions/1771786/question-mark-and-colon-in-javascript https://stackoverflow.com/questions/6259982/how-do-you-use-the-conditional-operator-in-javascript https://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript – VLAZ Apr 24 '20 at 15:20
  • The explicit parentheses in that example should make it quite trivial to parse. – Quentin Apr 24 '20 at 15:22
  • I agree it should, but im confusing myself. – Mathlearner Apr 24 '20 at 15:27

0 Answers0