Bad Parts
Based on Appendix B of "JavaScript: The Good Parts"
- == and != are bad. Always use === and !==
- with statement - avoid it
- eval - can be dangerous. Don't use it.
- continue - Douglas Crockford recommends to avoid it as you can write code without it.
- switch - Always break. Don't let it fall through.
- Block-less statement - always use {} after 'if'.
- ++ -- - Douglas Crockford recommends to avoid them. I think there are places where they can be used without problems.
- Bitwise operators - usually there is no need for them in JavaScript.
- Function statement vs Function expressions
- Typed Wrappers - avoid new Boolean, new Number, new String, new Array, new Object
- new - name constructor functions with leading capital letter, or even better: avoid using 'new'.
- void - avoid it
examples/js/function_statement.js
function add(x, y) { ... }
examples/js/function_expression.js
add = function (x, y) { ... };
A good way to enforce that everything is private is to wrap the whole code in an anonymous function expression, and execute it upon parsing it.
examples/js/global_function_expression.js
(function() { ... // No new global variables })();
The official ECMAScript grammar states, that if the first word is 'function' then it is part of a function statement, but this is a function expression. That why we add a pair of () around the function.