我正在关注browser detection的教程,该教程使用了两个!!
not运算符作为回报。我想知道使用2的意义是什么!!在代码中。
function supports_geolocation() {
return !!navigator.geolocation;
}
我相信!!navigator.geolocation === navigator.geolocation
。
如果没有,请纠正我,让我知道在这里使用两个not运算符的重要性。
答案 0 :(得分:1)
强制返回布尔值。
// navigator.geolocation is GeoLocation object
navigator.geolocation === true // return false
!!navigator.geolocation === true // returns true