Mona.V Mona.V - 8 months ago 39
Javascript Question

What does this line mean in JavaScript?

X=(x=== images.length-1) ? 0 : x+ 1;

Please help me I have no idea, and it's for a school task that I have to hand in.


I'm not sure why people are so opposed to just answering the question. It's a ternary operation. It's a shortcut for an if/else clause. For this particular operation,

Is x equivalent (===) to images.length-1? If so, set X to 0. Otherwise, set X to x + 1.

This pattern is likely used to endlessly iterate over an array (images). Once it reaches the end, it resets to the first element in the array.