How does the double exclamation (!!) work in javascript?

This question already has an answer here: What is the !! (not not) operator in JavaScript? 31 answers ! is the logical negation or "not" operator. !! is ! twice. It's a way of casting a "truthy" or "falsy" value to true or false , respectively. Given a boolean, ! will negate the value, ie !true yields false and vice versa. Given something other than a

双重感叹号(!!)如何在JavaScript中工作?

这个问题在这里已经有了答案: 是什么 !! (不)没有运算符在JavaScript中? 31个答案 ! 是逻辑否定或“不”运算符。 !! 是! 两次。 这是分别将“真实”或“虚假”值分别为true或false的一种方式。 给定一个布尔值! 将否定这个价值,即!true产生false ,反之亦然。 给定布尔值以外的值,该值将首先转换为布尔值,然后取反。 例如, !undefined将首先将undefined转换为false ,然后否定它,产生true 。 申请第二! 运算

Double negation (!!) in javascript

Possible Duplicate: What is the !! (not not) operator in JavaScript? I have encountered this piece of code function printStackTrace(options) { options = options || {guess: true}; var ex = options.e || null, guess = !!options.guess; var p = new printStackTrace.implementation(), result = p.run(ex); return (guess) ? p.guessAnonymousFunctions(result) : result; } And couldn'

JavaScript中的双重否定(!!)

可能重复: 是什么 !! (不)没有运算符在JavaScript中? 我遇到过这段代码 function printStackTrace(options) { options = options || {guess: true}; var ex = options.e || null, guess = !!options.guess; var p = new printStackTrace.implementation(), result = p.run(ex); return (guess) ? p.guessAnonymousFunctions(result) : result; } 并不禁想知道为什么双重否定? 还有一种替代方法可

Double exclamation points?

Possible Duplicate: What is the !! (not not) operator in JavaScript? What does the !! operator (double exclamation point) mean in JavaScript? So I was debuging some code and ran across this: var foo.bar = 0; // this is actually passed from another function, adding it for context function(foo) var someVar = !!foo.bar; if(foo.bar){ // ..stuff happens } else{ //

双感叹号?

可能重复: 是什么 !! (不)没有运算符在JavaScript中? 什么! 运算符(双重感叹号)在JavaScript中的意思是? 所以我正在调试一些代码并运行这个: var foo.bar = 0; // this is actually passed from another function, adding it for context function(foo) var someVar = !!foo.bar; if(foo.bar){ // ..stuff happens } else{ // .. something else happens } } 好的,我的

Can someone explain this 'double negative' trick?

This question already has an answer here: What is the !! (not not) operator in JavaScript? 31 answers A logical NOT operator ! converts a value to a boolean that is the opposite of its logical value. The second ! converts the previous boolean result back to the boolean representation of its original logical value. From these docs for the Logical NOT operator: Returns false if its si

有人可以解释这种“双重否定”的伎俩吗?

这个问题在这里已经有了答案: 是什么 !! (不)没有运算符在JavaScript中? 31个答案 一个逻辑NOT运算符! 将值转换为与其逻辑值相反的布尔值。 第二! 将之前的布尔结果转换回其原始逻辑值的布尔表示。 从逻辑NOT运算符的这些文档中: 如果其单个操作数可以转换为true,则返回false; 否则,返回true。 所以如果getContext给你一个“假”的价值, !! 将使它返回布尔值false 。 否则它将返回true 。 “虚假”的

what does << do in javascript

Possible Duplicate: Absolute Beginner's Guide to Bit Shifting? What is the JavaScript >>> operator and how do you use it? I came across << while reading some code. 1<<1 //2 2<<1 //4 3<<1 //6 3<<2 //12 What is this called? What does this do? Taken from this answer: Left shift (<<) Integers are stored, in memory, as a series of bits.

“在JavaScript中做什么?

可能重复: 绝对新手指南移位? 什么是JavaScript >>>运算符,你如何使用它? 我在阅读一些代码时遇到了<< 。 1<<1 //2 2<<1 //4 3<<1 //6 3<<2 //12 这个叫什么? 这是做什么的? 从这个答案采取: 左移(<<) 整数作为一系列位存储在内存中。 例如,存储为32位int的数字6将为: 00000000 00000000 00000000 00000110 将此位模式移动到左边的一个位置( 6 &l

What does << means in javascript

This question already has an answer here: What are bitwise shift (bit-shift) operators and how do they work? 8 answers It means bitwise left shift. Same as it means in most other programming languages. Some console test: >a = 2 2 >a << 1 4 >a << 3 16 It's the bitwise left operator. In a << b , it shifts a in binary representation b (< 32) bits to the

<<是什么意思在JavaScript中

这个问题在这里已经有了答案: 什么是位移(位移)操作符,它们是如何工作的? 8个答案 这意味着按位左移。 和其他大多数编程语言一样。 一些控制台测试: >a = 2 2 >a << 1 4 >a << 3 16 这是左边的运算符。 在a << b ,它转移a在二进制表示b (<32)比特的左边,从右侧的零移位。 一些例子: a = 1 // 00000001 in binary b = a << 1 // equals to 2, 00000010 in

What does << mean in Javascript

This question already has an answer here: What do “>>” and “<<” mean in Javascript? 10 answers What are bitwise shift (bit-shift) operators and how do they work? 8 answers what does << do in javascript [duplicate] 2 answers It's the bitwise left shift operator. The operands are converted to 32-bit integers, the left operand's bits are shifted left by the numbe

<<什么意思在Javascript中

这个问题在这里已经有了答案: Javascript中“>>”和“<<”是什么意思? 10个答案 什么是位移(位移)操作符,它们是如何工作的? 8个答案 在javascript中做什么[重复] 2个答案 这是按位左移运算符。 操作数被转换为32位整数,左操作数的位左移了右操作数定义的位数,表达式的值就是结果。 这里有一个简单的例子: var a = 1; var b = a << 2; // Move the bit left by two places console.log(b); /

Why does 2 == [2] in JavaScript?

I recently discovered that 2 == [2] in JavaScript. As it turns out, this quirk has a couple of interesting consequences: var a = [0, 1, 2, 3]; a[[2]] === a[2]; // this is true Similarly, the following works: var a = { "abc" : 1 }; a[["abc"]] === a["abc"]; // this is also true Even stranger still, this works as well: [[[[[[[2]]]]]]] == 2; // this is true too! WTF? These behaviors seem consi

为什么JavaScript 2中的2 == [2]?

我最近在JavaScript中发现了2 == [2] 。 事实证明,这个怪癖有一些有趣的结果: var a = [0, 1, 2, 3]; a[[2]] === a[2]; // this is true 同样,以下工作: var a = { "abc" : 1 }; a[["abc"]] === a["abc"]; // this is also true 即使是陌生人,这也适用: [[[[[[[2]]]]]]] == 2; // this is true too! WTF? 这些行为在所有浏览器中看起来都一致。 任何想法为什么这是一种语言功能? 这个“特征”会带来更多疯狂的后

How do I work around JavaScript's parseInt octal behavior?

Try executing the following in JavaScript: parseInt('01'); //equals 1 parseInt('02'); //equals 2 parseInt('03'); //equals 3 parseInt('04'); //equals 4 parseInt('05'); //equals 5 parseInt('06'); //equals 6 parseInt('07'); //equals 7 parseInt('08'); //equals 0 !! parseInt('09'); //equals 0 !! I just learned the hard way that JavaScript thinks the leading zero indicates an octal integer, and since

我如何解决JavaScript的parseInt八进制行为?

尝试在JavaScript中执行以下操作: parseInt('01'); //equals 1 parseInt('02'); //equals 2 parseInt('03'); //equals 3 parseInt('04'); //equals 4 parseInt('05'); //equals 5 parseInt('06'); //equals 6 parseInt('07'); //equals 7 parseInt('08'); //equals 0 !! parseInt('09'); //equals 0 !! 我刚刚学会了JavaScript认为前导零表示八进制整数的难题,并且由于基数8中没有"8"或"9" ,函数返回零

Triggering a video autoplay based on scroll position

I am writing a script that uses the Wipe animation from the scrollorama.js script. I am hoping to be able to implement a video to autoplay at certain markers in the scroll depth: ie, when a video page has wiped out another, and is now fully viewable. I have figured out how to measure scroll depth, i am successfully logging it in my console. I have figured out how to measure how deep i have scr

根据滚动位置触发视频自动播放

我正在编写一个使用scrollorama.js脚本中的Wipe动画的脚本。 我希望能够实现视频以自动播放滚动深度中的特定标记:即当视频页面已被另一个视频页面擦除时,现在可以完全观看。 我已经想出了如何测量滚动深度,我成功地将其记录在我的控制台中。 我已经想出了如何衡量我滚动的深度,但也许我太累了,我不知道如何让视频在滚动深度自动播放。 我希望这是一个法律问题,我可以得到一些帮助。 有没有人在那里试过这个? 这是迄