js double exclamation mark
// "!!" converts a value to a boolean, then inverts it and then inverts it again.
// So let's say you want to check the value for a given variable:
const num = null;
if (num) { // false -> value is null -> evaluated as falsy
}
if (!num) { // true
}
if (!!num) { // false
}
// another example
const str = "Hello World";
if (str) { // true -> value is a "proper" (not empty) string -> evaluated as truthy
}
if (!str) { // false
}
if (!!str) { // true
}
javascript double question mark
let a = null;
const b = a ?? -1; // Same as b = ( a != null ? a : -1 );
console.log(b); // output: -1
//OR IF
let a = 9;
const b = a ?? -1;
console.log(b); // output: 9
//PS.,VERY CLOSE TO '||' OPERATION IN FUNCTION, BY NOT THE SAME
double exclamation mark javascript
Double Exclamation