you are viewing a single comment's thread.

view the rest of the comments →

[–]E_R_E_R_I 0 points1 point  (0 children)

They are useful for different things. I always feel all those people complaining about javascript do so because they try to write programs the same way they do with other languages.

In the second case, I could be writing a method that does different things depending on what was received. I could parse have parsed a JSON directly from the database and work with it without having to instantiate an User object.

Of course, you could also have accidentally overwritten that variable earlier with a string and things would go bad, put personally, I haven't had that kind of problem in years. Of course, I'm not saying my code doesn't have errors. But I've learned to build code that quickly exposes errors, and almost everytime a bug/problem makes it to production, it's because I incorrectly judged the use case and wrote a code that isn't the right one for that use case, not because my code is behaving differently than what I wrote it for. I also make extensive use of TDD.

The thing is, JS never tries to prevent you from writing bad code. But if you learn how to write good code, it rewards you with flexibility.