1

What is difference in between !!user.rank and !user.rank

<div ng-show="!!user.rank">
    Rank: {{user.rank}}
</div>


<div ng-show="!user.rank">
    <button class="btn btn-success" ng-click="KnightMe(user)">Knight       Me</button>
</div>
Bharat Joshi
  • 179
  • 1
  • 3
  • 14

2 Answers2

2

! is not operator
!! casts something to truthy / not truthy

var foo = 0;
console.log(!!foo);
//false
GN.
  • 4,948
  • 7
  • 36
  • 70
1

! converts Object to boolean. If it was falsey (e.g. 0, null, undefined, etc.), it will be false, otherwise, true.

!oObject  //Inverted boolean
!!oObject //Non inverted boolean so true boolean representation

So !! is not an operator, it's just the ! operator twice

see the detailed question and answer here

Community
  • 1
  • 1
Abdullah Al Noman
  • 2,627
  • 15
  • 34