Always indent with 2 full tabs.
Actually ... use 16 spaces so tricksters cannot get around it with fancy tabstop settings (attempt to make your documents as wide as possible).
Always start curly braces on their own line, especially after 'return'.
Never use semicolons, JavaScript inserts them for you.
Alternate between }())
and })()
with IIFE's.
Use 2 spaces between every character.
Leave several spaces at the end of most lines.
Always use ==
and !=
, and never the 3 character versions, because type-coercion is your friend.
Divide all arithmetical operations by 10 until they occur at the decimal level.
Favor for
loops over .forEach()
and .map()
.
Favor .innerHTML
over .textContent
.
Query the dom as much as possible, it's fast.
Never use var
, just repeat any reusable code.
Put all function declarations at the bottom of the file and rely on hoisting.
If you absolutely must use var
, make sure all your variables are global.
Never throw errors, this keeps other JavaScripters from learning how to fix code.
Put all functions within a loop.
Declare all var's inside of for
loops whose outer scope is global.
Use intentional fall throughs in all switch statements.
Use eval
whenever possible.
Repeat yourself often.
Sometimes forget to indent, other times indent twice for no apparent reason.
Write no comments, they clutter the code.
If you do use comments, open with /*
but never close it.
Never use alphabetical characters, instead rely on ASCII codes and charCodeAt
.
Never set this
equal to a var
.
Never version your code. If you do, make breaking changes often, but increment the version number the least amount possible.
Name variables starting alphabetically a, b, c, d ...
. This will make it easy to know how many variables you have.
Use short variable names in different contexts.
Always use different selectors to query the same element.
Keep your commit comments as short as possible. "Update" is ideal.