JavaScript:“ !!”是什么意思?

php_nub_qq

我刚遇到这个

var strict = !! argStrict;

我不禁想知道,这是什么意思!!是双重否定的吗?似乎很多余php.js,这种情况下的家伙不太可能会使用它吗?

来源:http//phpjs.org/functions/in_array/

克里斯·沃尔什

它强制类型变为真正的布尔值,而不是“真实”值。例子:

var a = (1 === true) // comes out as false because 1 and true are different types and not exactly the same

var b = ((!!1) === true) // comes out as true because the 1 is first converted to a boolean value by means of negation (becomes false) and then negated a second time (becomes true)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档