Airbnb javascript coding styles
string
, number
, boolean
, null
, undefined
, symbol
, bigint
)object
, array
, function
)const
for all references; avoid var
let
only if reassigning referencesconst
and let
are block-scoped, unlike function-scoped var
Object.prototype
methods directly{...obj}
) over Object.assign
Array#push
instead of direct assignment...
to copy arrays...
for iterable conversion; Array.from
for array-like objects''
) for stringseval()
on stringsarguments
...
) instead of arguments
class
syntax; avoid manipulating prototype
directlyextends
for inheritancethis
for method chainingthis
or be staticimport
/export
) over non-standard module systems[]
when accessing properties with a variable**
) when calculating exponentiationsconst
or let
, never undeclared variablesconst
s and then all let
s++
, --
)=
in assignments===
and !==
over ==
and !=
??
) only for null
/undefined
caseselse
on same line as closing brace of if
else
blocks when if
contains a return/** ... */
for multiline comments//
for single line comments above the subjectFIXME:
or TODO:
for actionable itemsString()
, Number()
, parseInt()
, Boolean()
this
; use arrow functions or bindget
, set
, is
, has
appropriately$