~
flips all the bits in a number. Flipping every bit twice, gives you back the same bits, so the number stays the same.
!
gives you zero when applied to a non-zero operand and one when applied to zero. So if the operand is one or zero, it will give you back the same operand. But when the operand is neither one nor zero, it will give you back one instead of the original number.
So ~~
always gives you the original number and !!
gives you one or zero.