我现在正在读《发现 meteor 》, 第7章有代码:
Posts.allow({
insert: function(userId, doc) {
// only allow posting if you are logged in
return !! userId; ///// <<==== what does "!!" means?
}
});
谢谢
最佳答案
汤姆·里特 (Tom Ritter) 精彩地总结为
// Maximum Obscurity:
val.enabled = !!userId;
// Partial Obscurity:
val.enabled = (userId != 0) ? true : false;
// And finally, much easier to understand:
val.enabled = (userId != 0);
因此先转换为 bool 值,然后进行双重否定
关于javascript - 这个语法在 JavaScript 中意味着什么 -----> "!! "?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19130434/