Do you know what will be the output of this code?
JavaScript
if ([]) {
console.log("yes");
} else {
console.log("no");
}
Show answer and explanation
The answer is yes.
All objects are truthy, and arrays are objects, even when empty. The only falsy values are false, 0, -0, 0n, "", null, undefined and NaN.
To check for an empty array, use arr.length === 0.