Are there any shorter and trickier codes in javascript?

I found the following short and tricky codes for

Double Bitwise NOT (~~) - James Padolsey
http://james.padolsey.com/javascript/double-bitwise-not/

Web Reflection: two simple JavaScript tricks (old but always useful )
http://webreflection.blogspot.com/2008/06/two-simple-tricks-in-javascript-olds.html


double bitwise
Math.round(v)=== ~~v

Math.floor(v)=== ~~v(if v> 0)

isNaN(Number(v)) ? 0 : Number(v)=== ~~v(if v does not float )


double non

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 any shorter or more complex codes in javascript?

+3
source share

All Articles