Our great sponsors
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
That wasn't the point of this exercise - nobody is saying that these are actual code is examples you'd see in real life.
The point is that in lots of languages these statements would simply result in compile time errors. In JS, though, the type coercion rules are so loose (and in many cases extremely non-obvious) that you can see this head scratching behavior.
It's the same underlying behavior that leads to very cool/very insane stuff like JSFuck: https://jsfuck.com/
Someone should write a book about this [0] and a tool to automate checking your JavaScript code [1].
[0]: https://www.oreilly.com/library/view/javascript-the-good/978...
[1]: https://www.jslint.com/
I'm working on a book called "How to not get your knickers in a twist because you neglected to learn from people who came before you."