Ternary operator displays error in JSHint - Expected an assignment or function call and instead saw an expression

javascript

Solution

You are misusing the conditional operator as an `if` statement, that's why you are getting that note. The real work in the code is done as a side effect of the expression, and the result of the expression is ignored.

As a real `if` statement, it would be:

if (dir === 'next') {
  ++$currentSlide;
} else {
  --$currentSlide;
}

You can use the conditional operator if you use it as an actual expression:

$currentSlide += dir === 'next' ? 1 : -1;

Problem

I have a ternary operator `dir === 'next' ? ++$currentSlide : --$currentSlide;` in my JS used to increment of decrement an integer. when I run my script in grunt JSHint hightlights this line as `Expected an assignment or function call and instead saw an expression.` Can anyone advise where I'm going wrong with this? Should I set my condition up differently etc?

Original source