The JavaScript guidelines are mostly equal to PHPs coding guidelines.
We ever use full self explaining names for variables, constants, class- and method names etc.
Do:
let calculationResult = 0,
counter = 0;
calculateResult()
{
// Do things
}Don't:
let cRes = 0,
cnt = 0;
calcRes()
{
// Do things
}For booleans we prefix variables with is has can verbs.
var isAuthorized = false,
canVote = false;Filenames equals the classnames FooBarCalculation.js equals class FooBarCalculation { }
We place curly braces in every case on the next line.
Classes
class FileAdapter extends Adapter
{
// Do things
}If-Else
// Comment A
if (a === b)
{
// Do things
}
// Comment B
else
{
// Do other things
}For-Each
items.forEach(function(value, index))
{
// Do things
}For private methods we use the _ prefix
calculateResult()
{
// Do things
}
_getValueItem()
{
// Prefixed
}if ( ! firstValue)
{
// Do things
}// TODO: Check conditions
// FIXME: When $item is null ...Use single quotes for strings as a default (exception proves the rule).