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

1. Don't use with. It's hard to reason about, and it breaks many compiler optimizations (you're adding a dynamic object into the scope chain).

2. Just don't ever use == or !=. Forget they exist. Done.



I've always found == to be very useful when comparing undefined, because undefined == null. It's very rare that I want to treat undefined and null separately (unless one or the other means there was an error earlier).


That's the only reasonable use for ==, IMO.


I recently added my own syntax rule to JavaScript mode in Emacs to highlight lone { at the beginning of line (with or without trailing whitespaces). After your comment, I think about adding some more highlights for with, == and !=.


Are there any other hard and fast rules I should be aware of?


Are there ever. Read "JavaScript: The Good Parts" or watch the lectures by the same name on YouTube.




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

Search: