-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
  • 460,746
  • 196
  • 858
  • 974
  • 2
    I don't think this answer should be downvoted, it's not wrong. But the whole QA should certainly be removed as useless. @SeamusOConnor Did you even google "exclamation javascript" ? – Denys Séguret Jan 18 '16 at 16:54
  • I googled "what does the ! mean in Angular?" just didn't think of actually writhing exclamation mark. I know a little stupid of me but hardly worth a minus 7 downgrade as if I asked the worst question in the world.... Thanks for the answer btw...... Won't be asking a question in future – Seamus O Connor Jan 18 '16 at 16:57