-7

I was wondering what does the ! actually mean in this method

 $scope.toggleSelected = function () {
      $scope.selected = !$scope.selected;
    };

I understand it's allowing me to set a selected item and it won't work without it but what exactly is the ! for?

Seamus O Connor
  • 83
  • 1
  • 1
  • 7
  • Do you know what `toggle` means? This is what `!` is for, toggling between `true` and `false`. – Sergio Tulentsev Jan 18 '16 at 16:50
  • it mean, as in many other langage, the opposite of a boolean expression. !true => false. – AlainIb Jan 18 '16 at 16:50
  • [logical NOT operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_NOT_%28!%29) – charlietfl Jan 18 '16 at 16:50
  • you should read about basic operator, like '&' , '|' , '&&', '||' , '!' , '++' ... – AlainIb Jan 18 '16 at 16:51
  • Called Logical NOT Operator. It is used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false. – Hasta Tamang Jan 18 '16 at 16:51

1 Answers1

1

The ! is the normal negation operator.

Inside of that function, it's used to flip/toggle the value each time it's called. For example, from true to false and vice-versa.

alex
  • 479,566
  • 201
  • 878
  • 984