Page 1 of 1

Javascript ~~

Posted: Fri Jan 02, 2015 9:05 pm
by Mardonis
What do the squigglies mean in javascript? I have tried googling for "Javascript ~~". All that comes up is what javascript is. Not what the ~~ mean in Javascript.

Re: Javascript ~~

Posted: Fri Jan 02, 2015 10:48 pm
by Xaos
The squiggle is a tilde. The tilde in javascript is used for bit shifting.

~(5.5) // => -6
~(-6) // => 5
~~5.5 // => 5 (same as Math.floor(5.5))
~~(-5.5) // => -5 (NOT the same as Math.floor(-5.5), which would give -6 )


http://stackoverflow.com/questions/5971 ... javascript

Re: Javascript ~~

Posted: Sat Jan 03, 2015 8:51 pm
by Jackolantern
Of course, in client-side JS, there are only a small handful of use cases for bitwise operations because JS does not handle binary data by default. Most of the time bitwise operations are useful for working directly with binary. It is an afterthought that they are in client-side JS at all. XOR could have some usage for encryption, but since the salt is in plain text on the client, what's the point?