JavaScript's unexpected truthy behavior with arrays and false.

Did you know this about JavaScript? In JavaScript: [ ] == ![ ] is true. Wait, what? Here’s why: ![ ] becomes false because an empty array is truthy. So the expression becomes [ ] == false. JavaScript tries to convert both sides to the same type. Number([ ]) is 0, and Number(false) is also 0. Therefore, 0 == 0 → true. This is one of the reasons developers say: "JavaScript is simple… until it isn’t." I’m currently learning JavaScript and finding these little quirks really fascinating. If you’re also learning, what’s the weirdest or most surprising thing you’ve discovered so far? #JavaScript #WebDevelopment #CodingJourney #100DaysOfCode #DidYouKnow #LearnInPublic #FrontendDevelopment

  • graphical user interface

To view or add a comment, sign in

Explore content categories