Tutorial by Examples

The following example illustrates use of the bitwise NOT (~) operator on integer numbers. let number = 3; let complement = ~number; Result of the complement number equals to -4; ExpressionBinary valueDecimal value300000000 00000000 00000000 000000113~311111111 11111111 11111111 11111100-4 To ...
Double Tilde ~~ will perform bitwise NOT operation twice. The following example illustrates use of the bitwise NOT (~~) operator on decimal numbers. To keep the example simple, decimal number 3.5 will be used, cause of it's simple representation in binary format. let number = 3.5; let complement...
~~ Could be used on non-numeric values. A numeric expression will be first converted to a number and then performed bitwise NOT operation on it. If expression cannot be converted to numeric value, it will convert to 0. true and false bool values are exceptions, where true is presented as numeric v...
We can use ~ as a shorthand in some everyday scenarios. We know that ~ converts -1 to 0, so we can use it with indexOf on array. indexOf let items = ['foo', 'bar', 'baz']; let el = 'a'; if (items.indexOf('a') !== -1) {} or if (items.indexOf('a') >= 0) {} can be re-written as if (...
The following example illustrates use of the bitwise NOT (~) operator on decimal numbers. To keep the example simple, decimal number 3.5 will be used, cause of it's simple representation in binary format. let number = 3.5; let complement = ~number; Result of the complement number equals to -4;...

Page 1 of 1