- Put each statement on its own line(s)
- Don't add
;
at the end of your statements - If your statement is impure; mark it with a
;
in the front!- Why? Javascript expressions always play well with Automatic Semi-colon Insertion. It is the prefixes in statements which potentially cause problems (e.g.
hello () \n [] .forEach (...)
on the next line is confused withhello () [] .forEach
, which gives errors likeUnexpected token ]
). So we can safely escape statements, and only statements! And the only statements that are not 'impure' are variable assignments, which also respect Automatic Semi-colon Insertion. - e.g. No
console .log (x)
. It's impure, so;console .log (x)
- Why? Javascript expressions always play well with Automatic Semi-colon Insertion. It is the prefixes in statements which potentially cause problems (e.g.
- If your function is impure; make it
{;}
!- e.g. No
x => console .log (x)
. It's impure, sox => {;console .log (x)}
- e.g. No
- Don't use
this
, userequire ('thiss')
- No function statements
- Make your functions generic. Use
x
,y
,z
,t
,u
,v
,w
, q,
r, s
, ... for the parameters (Unless they are really specific, obviously unreusable)- What is this? basically the 'ABC' song triplets/quadruplets/quintuplets
- Add spaces between tokens
- Avoid suffixes smaller than the prefix. It is undiscoverable.
- e.g. This is bad. The significant call operator
()
is undiscoverable! Is this a function or the value?
- e.g. This is bad. The significant call operator
var result = (x => {
...
var computation = step_1 + step_2
return result
}) ()
- Mark your sentence with the one significant prefix (if its in a phrase), hide the rest on the previous line. Encourage the leading member to follow the
[
or(
- e.g. (the prefix here is
o
)
- e.g. (the prefix here is
var result = Oo (something,
o (x => x .parent),
o (R .reduce ((sum, x) => sum + x, 0)))
or
var q = [ document .querySelector ('fire')
, document .querySelector ('earth')
, document .querySelector ('air')
, document .querySelector ('water') ]
- Collapse the
)
s,}
s, etc.
- Use tabs
- Use single quotes
''
- Use snake_case (since hyphen-case does not work)
- Do add a space before
.
. The property is a word!- e.g.
document .body .style .backgroundImage = 'url(doge.png)'
- e.g.
- Use arrow functions, and only arrow functions!
- Arrow functions with one parameter, take no brackets
- Curry!
- Use
var
, andvar
only - Try to not mutate
var
s - No class statements
- Write your unfinished code as
...