Imi Imi - 1 month ago 15
AngularJS Question

what does =! means in javascript

I came across this line while reading source code of an application.

$scope.editMode = ! $scope.editMode;


I wonder what does this is not the not the not equal to operator. I tried it in this jsfiddle the answer is correct but I still do not understand the logic is this somehow an equal to operator?

jsfiddlecode

$scope.name = 'Superhero';
$scope.hero = '123'
$scope.name = ! $scope.hero

Answer

! is used to reverse boolean value. For example:

!(true) = false and 
!(false) = true

In your example

$scope.editMode has assigned to reversion of $scope.editMode

Comments