Search code examples
javascriptangularjsconditional-statementsnull-check

java script or angularjs condition check on object with "!" vs "!!"


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


Solution

  • 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?