Home  >  Q&A  >  body text

javascript - Some problems with ternary operator

阿神阿神2662 days ago781

reply all(3)I'll reply

  • 習慣沉默

    習慣沉默2017-07-05 10:46:02

    See inside the black box, the value of la here is 0. In the sentence you marked, la == 0 ? 1 : la - 1, the output value is indeed 1 (because la == 0 established), but there is no place in this line to assign a value to la, so the value of la will not change and is still 0.

    reply
    0
  • ringa_lee

    ringa_lee2017-07-05 10:46:02

    la == 0 ? la = 1 : la - 1

    reply
    0
  • 黄舟

    黄舟2017-07-05 10:46:02

    la==0?1:la-1

    This statement does nothing at all and needs to be changed to;

    la=la==0?1:la-1

    reply
    0
  • Cancelreply