I found the following short and tricky codes on
Double bitwise NOT (~~) – James Padolsey
http://james.padolsey.com/javascript/double-bitwise-not/
Web Reflection: Two simple tricks in JavaScript ( olds, but always useful )
http://webreflection.blogspot.com/2008/06/two-simple-tricks-in-javascript-olds.html
double bitwise not
Math.round(v) === ~~v
Math.floor(v) === ~~v (if v > 0)
isNaN(Number(v)) ? 0 : Number(v) === ~~v(if v is not float)
double not
Boolean(v) === !!v
(!Boolean(v) === !v)
bitwise shift
Math.round(v / 2) === v >> 1
Math.round(v) === v >> 0
single bitwise not
a.indexOf(v) !== -1 === ~a.indexOf(v)
Are there more short or tricky codes in javascript?
These “tricks” are not specific to Javascript.
A simple search on Google will return a number of pages offering tricks similar.
http://resnet.uoregon.edu/~gurney_j/jmpc/bitwise.html
http://lab.polygonal.de/2007/05/10/bitwise-gems-fast-integer-math/
http://www.beyond3d.com/content/articles/8/