变量上有两个not(!!)运算符的用法是什么

时间:2015-10-31 18:28:16

标签: html geolocation not-operator

我正在关注browser detection的教程,该教程使用了两个!! not运算符作为回报。我想知道使用2的意义是什么!!在代码中。

function supports_geolocation() {
  return !!navigator.geolocation;
}

我相信!!navigator.geolocation === navigator.geolocation

如果没有,请纠正我,让我知道在这里使用两个not运算符的重要性。

1 个答案:

答案 0 :(得分:1)

强制返回布尔值。

// navigator.geolocation is GeoLocation object
navigator.geolocation === true // return false
!!navigator.geolocation === true // returns true