Our code :-
Step 1: Evaluate Right-Hand Side – ![]
![]
means: logical NOT of an array
But wait — is an array []
truthy or falsy?
In JavaScript, all objects are truthy, including empty arrays.
So:
👉 So now the expression becomes:
Step 2: Coerce Both Sides – [] == false
Now we’re comparing:
[]
→ objectfalse
→ boolean
Rule:
When comparing an object with a primitive using ==
, JavaScript:
- Tries to convert the object to a primitive (usually a string or number)
So:
Now it becomes:
Step 3: Compare "" == false
Now both sides are primitives, but different types:
""
is a stringfalse
is a boolean
Again, JavaScript tries to coerce them to numbers:
So it becomes:
✔ Final Answer:
A) true
This question appeared in the TCS 2nd round of interview, testing the candidate’s knowledge of comparisons operator between arrays with inversion operator in JavaScript.