-4

While refactoring I mistakenly put two dash -- before > and the code seems to work without any error. I checked MDN Operators page but could not find a relevant definition. Can you please let me know what is this operator called.

function checkSitOccupancy(n) {
  while (n --> 0)
    console.log(n);
}
checkSitOccupancy(2)
brk
  • 48,835
  • 10
  • 56
  • 78
  • 3
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Decrement –  Feb 07 '19 at 16:09
  • 2
    `--` and `>` are two separate operators. Space or no space, they are not one operator. –  Feb 07 '19 at 16:09
  • `n--` means `n=n-1` , then you use the bigger than operator ´>´ afterwards – MikNiller Feb 07 '19 at 16:09

4 Answers4

1

while (n-- > 0) means "while decremented value of n is greater than zero"

jmargolisvt
  • 5,722
  • 4
  • 29
  • 46
0

There is no --> operator. You are just decreasing n and comparing if > 0

GabrieleMartini
  • 1,665
  • 2
  • 19
  • 26
0

It is the decrement operator.

It decrements the value of n and compares it with a greater than operator

Dhananjai Pai
  • 5,914
  • 1
  • 10
  • 25
-1

That's the decrement operator, subtraction's analog to ++.

EDIT: In your case above, you've squeezed a decrement and greater than sign together, making them appear to be a single operator; they're not, as javascript doesn't need the white space.

ajm
  • 19,795
  • 3
  • 32
  • 37