It reverses the boolean result of the operand (or condition).
result = !value;
The following operator accepts only one argument and does the following:
- Converts the operand to boolean type i.e true/false
- returns the flipped value
The operator converted the value ‘1’ to boolean and it resulted in ‘true’ then after it flipped(inversed) that value and that’s why when we finally alert the value we get ‘false’.
The && operator accepts mutilple arguments and it mainly does the following:
- Evaluates the operands from left to right
- For each operand, it will first convert it to a boolean. If the result is false, stops and returns the original value of that operand.
- otherwise if all were truthy it will return the last truthy value.
result = a && b; // can have mutiple arguments.
0 3 null 4
The ‘OR’ operator is somewhat opposite of ‘AND’ operator. It does the following:
- evaluates the operand from left to right.
- For each operand, it will first convert it to a boolean. If the result is true, stops and returns the original value of that operand.
- otherwise if all the values are falsy, it will return the last value.
result = a || b;
1 1 true -1