-1

Can anyone explain, the difference between

<div ng-show="!user.name"> and <div ng-show="!!user.name">

I was wondering what

!!

does? in angularjs I googled it but didn't get relivent answer

Uttam Ughareja
  • 842
  • 2
  • 12
  • 21
  • It is a double negative. `true` evals to `true`; `!true` evals to `false`, `!!true` evals to `true`; `!!!true` evals to `false`; ....and you can keep going if you want. The main use is to take a truthy value and make it return a boolean true or false. – Igor Aug 24 '18 at 11:18

1 Answers1

2

It is a double logical not operator.

  • true evals to true

  • !true evals to false

  • !!true evals to true

  • !!!true evals to false

    ....and you can keep going if you want.

The main use of !! generally is to take a truthy value and have it result in a boolean true or false.


logical not operator ! Returns false if its single operand can be converted to true; otherwise, returns true


See also What is the !! (not not) operator in JavaScript?

Community
  • 1
  • 1
Igor
  • 60,821
  • 10
  • 100
  • 175