java 脚本或 angularjs 条件检查带有“!”的对象vs "!!"

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

谁能解释一下

的区别

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

我想知道

!!

是吗?在 angularjs 我用谷歌搜索但没有得到相关的答案

它是双logical not operator

  • true 计算为 true

  • !true 计算为 false

  • !!true 计算为 true

  • !!!true 计算为 false

    ..如果你愿意,你可以继续。

!! 的主要用途通常是取一个 truthy value 并使其产生布尔值 truefalse.


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


另见 What is the !! (not not) operator in JavaScript?