Javascript ~~

C++, C#, Java, PHP, ect...
Post Reply
Mardonis
Posts: 139
Joined: Wed Jun 29, 2011 7:54 pm

Javascript ~~

Post 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.
User avatar
Xaos
Posts: 946
Joined: Wed Jan 11, 2012 4:01 am

Re: Javascript ~~

Post 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
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Javascript ~~

Post 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?
The indelible lord of tl;dr
Post Reply

Return to “Coding”