JavaScript Array Comparison Trick

🚨 JavaScript Trick Question (Looks Easy… Isn’t 👀) What will be the output? console.log([] == ![]); Take a second before answering. Most developers get this wrong at first glance 😅 👉 What do you think the output will be? 👉 Bonus: Can you explain why? #JavaScript #FrontendInterview #WebDevelopment #FrontendDeveloper #Coding

True. Because [] is truthy. ![] evaluates to "false" Now, it's: [] == false As we're comparing loose equality JS does Type Coercion which means: [] -> "" -> 0 false is also "0' Hence, 0 == 0 (true).

To view or add a comment, sign in

Explore content categories