Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I would agree if wasn't for the fact that JS is a dynamically typed language.

You can (and sometimes will) run into instances of this without noticing, because while you won't explicitly write

  true++
you might do something like

  x = someFunction()
  x++
not realising that someFunction() might return a boolean under some circumstances.

Anyone who worked with a sufficiently large JS codebase ran into one of these cases and got unexpected results at some point due to this.



true++ and x++ are syntactically different though. The latter is a post-increment of an identifier, and the former is a post-increment of a boolean literal. Different rules may apply to these cases.


This is true, one must always make sure to handle all possible return types, but that's true for all dynamic languages.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: