โbitwise not (~)
๐ง under construction -> code example
JS โฉ statement โฉ expression โฉ operator โฉ arithmetic โฉ bitwise โฉ not
(converts the operand to a 32-bit signed integer)
inverts the bits of its operand. (definition๏ผ ~x = -x - 1
, ๐ 2's complement)
// โญ `~x` === -x - 1 (if x integer, truncate decimal if not)
~(3), // -4 (-3 - 1)
~(-5), // 4 ( 5 - 1)
~(3.4), // -4 ( 3.4 -> 3 -> -3 - 1 = -4)
~(-5.5), // 4 (-5.5 -> -5 -> 5 - 1 = 4)
// โญ `~~x`: nearest integer towards 0.
~~(7.8), // 7
~~(-3.4), // -3
~~(6), // 6 (โญ `~~x = x`, if x integer)
๐ table of operators
replit๏ผ bitwise not (~) (v.2)
โโโ (+x !== ~~x)
โ
โ x type +x ~~x ~x โญ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
null Null 0 0 -1
โญ undefined Undefined NaN 0 -1
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
true Boolean 1 1 -2
false Boolean 0 0 -1
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
'' String 0 0 -1
'23' String 23 23 -24
โญ 'yes' String NaN 0 -1
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1 Number 1 1 -2
0 Number 0 0 -1
โญ NaN Number NaN 0 -1
โญ Infinity Number Infinity 0 -1
โญ -Infinity Number -Infinity 0 -1
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 40n BigInt TypeError 40 -41
โ Symbol() Symbol TypeError TypeError TypeError
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โญ ({a:1}) Object NaN 0 -1
โญ ({}) Object NaN 0 -1
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
[] Array 0 0 -1
โญ [4.5] Array 4.5 4 -5
โญ ['-7.8'] Array -7.8 -7 6
โญ [1,2,3] Array NaN 0 -1
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โญ /regex/ RegExp NaN 0 -1
โญ new Date Date 1667543819273 1096508425 -1096508426
โญ ()=>{} Function NaN 0 -1
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Last updated
Was this helpful?