๐ JavaScript Tilde ~ (Bitwise NOT Operator): The Switch Flipper

Once upon a time, in the digital kingdom, there was a mischievous wizard named Tilde. Tilde loved going into rooms full of glowing switchesโsome ON (1), some OFF (0). But he had only one rule: ๐ He flipped every single switch he saw.
- If a switch was ON (1), he turned it OFF (0).
 - If a switch was OFF (0), he turned it ON (1).
 
This magical flipping is exactly what the tilde operator (~) does in JavaScript.
What Does ~ Do?
The tilde is a bitwise NOT operator.
- It looks at every bit (1s and 0s) of a number.
 - Then it flips them: 1 โ 0, 0 โ 1.
 
Example:
let x = 5;      // 00000101 in binary
console.log(~x); // 11111010 in binary โ -6
Whoa! How did 5 become -6? Thatโs because in computers, negative numbers are stored in a special binary format called twoโs complement. When you flip all the bits of 5, you actually get -6.
So Whatโs the Use of ~?
Even though it seems strange, the tilde has some clever uses:
- 
    
Quickly turn positives into negatives (and vice versa).
~xis basically the same as-(x + 1).
 - 
    
Check if a number is NOT found in a list.
- For example, in old-school coding, 
indexOfreturns-1if something isnโt found. - Using 
~indexwas a clever shortcut to check this. 
 - For example, in old-school coding, 
 
Example:
let fruits = ["apple", "banana", "mango"];
console.log(~fruits.indexOf("banana")); // Not -1 โ true
console.log(~fruits.indexOf("grape"));  // -1 โ 0 โ false
Real-Life Analogy
Think of Tilde as a prankster who sneaks into a classroom with light switches.
- If the light is ON, he turns it OFF.
 - If the light is OFF, he turns it ON.
The room looks completely opposite after heโs doneโjust like numbers after applying 
~. 
In Short
~= Bitwise NOT operator.- Flips all bits: 1 โ 0, 0 โ 1.
 ~xequals-(x + 1).- Useful in quick tricks like checking 
indexOf. 
Review Questions
- The tilde (
~) operator is also called the __________ NOT operator. - The tilde flips every __________ of a number.
 - If a bit is 1, tilde turns it into __________.
 - If a bit is 0, tilde turns it into __________.
 - In binary, 
5 (00000101)becomes __________ after applying~. ~xis the same as __________ in math form.indexOf()returns __________ when an item is not found in an array.- Using 
~indexis a coding shortcut for checking if something is __________. - A real-life analogy for tilde is a prankster flipping all the __________ in a classroom.
 - The tilde operator is written as the symbol __________.