Code Style Guide
Note:
This guide assumes you are using Babel, and requires that you use babel-preset-airbnb or the equivalent. It also assumes you install shims/polyfills in your app with airbnb-browser-shims or the equivalent.
This Guide is based on the Airbnb javascript style guide.
Table of Contents
Quick Tips
Prefer meaningful variable and function names
❌ Bad:
✅ Good:
Write small, pure functions
❌ Bad:
✅ Good:
Use consistent indentation and formatting
❌ Bad:
✅ Good:
DRY (Don't Repeat Yourself)
❌ Bad:
✅ Good:
Use strict equality (
===and!==)❌ Bad:
✅ Good:
Use early returns in functions
❌ Bad:
✅ Good:
Avoid deeply nested code
❌ Bad:
✅ Good:
Types
1.1 Primitives: When you access a primitive type, you work directly on its value. (Pass by Value)
stringnumberbooleannullundefinedsymbolbigint
Symbols and BigInts cannot be faithfully polyfilled, so they should not be used when targeting browsers/environments that don’t support them natively.
Polyfill is a term that originated from combining "poly," meaning many, and "fill," implying filling in the gaps. In the context of web development and programming with JavaScript, a polyfill is a piece of code that provides modern functionality on older browsers that do not naturally support it.
When a new web standard or API is introduced, it may take some time for all browsers to fully implement and support it. During this transition period, developers may use polyfills to ensure that their code works consistently across different browsers.
1.2 Complex: When you access a complex type you work on a reference to its value. (Pass by Reference)
objectarrayfunction
References
2.1 Use
constfor all of your references; avoid usingvar. eslint:prefer-const,no-const-assignWhy? This ensures that you can’t reassign your references, which can lead to bugs and difficulty comprehending code.
2.3 Note that both
letandconstare block-scoped, whereasvaris function-scoped.The above code shows that referencing
aandbwill produce a ReferenceError, whileccontains the number. This is becauseaandbare block-scoped, whilecis scoped to the containing function.
Objects
3.1 Use the literal syntax for object creation. eslint:
no-new-object3.2 Use computed property names when creating objects with dynamic property names.
Why? They allow you to define all the properties of an object in one place.
3.3 Use object method shorthand. eslint:
object-shorthand3.4 Use property value shorthand. eslint:
object-shorthandWhy? It is shorter and descriptive.
3.5 Group your shorthand properties at the beginning of your object declaration.
Why? It’s easier to tell which properties are using the shorthand.
3.6 Only quote properties that are invalid identifiers. eslint:
quote-propsWhy? In general we consider it subjectively easier to read. It improves syntax highlighting, and is also more easily optimized by many JS engines.
3.7 Do not call
Object.prototypemethods directly, such ashasOwnProperty,propertyIsEnumerable, andisPrototypeOf. eslint:no-prototype-builtinsWhy? These methods may be shadowed by properties on the object in question - consider
{ hasOwnProperty: false }- or, the object may be a null object (Object.create(null)). In modern browsers that support ES2022, or with a polyfill such as https://npmjs.com/object.hasown,Object.hasOwncan also be used as an alternative toObject.prototype.hasOwnProperty.call.3.8 Prefer the object spread syntax over
Object.assignto shallow-copy objects. Use the object rest parameter syntax to get a new object with certain properties omitted. eslint:prefer-object-spread
Arrays
4.1 Use the literal syntax for array creation. eslint:
no-array-constructor4.2 Use Array#push instead of direct assignment to add items to an array.
4.3 Use array spreads
...to copy arrays.4.4 To convert an iterable object to an array, use spreads
...instead ofArray.from4.5 Use
Array.fromfor converting an array-like object to an array.4.6 Use
Array.frominstead of spread...for mapping over iterables, because it avoids creating an intermediate array.4.7 Use return statements in array method callbacks. It’s ok to omit the return if the function body consists of a single statement returning an expression without side effects, following 8.2. eslint:
array-callback-return4.8 Use line breaks after opening array brackets and before closing array brackets, if an array has multiple lines
Destructuring
5.1 Use object destructuring when accessing and using multiple properties of an object. eslint:
prefer-destructuringWhy? Destructuring saves you from creating temporary references for those properties, and from repetitive access of the object. Repeating object access creates more repetitive code, requires more reading, and creates more opportunities for mistakes. Destructuring objects also provides a single site of definition of the object structure that is used in the block, rather than requiring reading the entire block to determine what is used.
5.2 Use array destructuring. eslint:
prefer-destructuring5.3 Use object destructuring for multiple return values, not array destructuring.
Why? You can add new properties over time or change the order of things without breaking call sites.
Strings
6.2 Strings that cause the line to go over 100 characters should not be written across multiple lines using string concatenation.
Why? Broken strings are painful to work with and make code less searchable.
6.3 When programmatically building up strings, use template strings instead of concatenation. eslint:
prefer-templatetemplate-curly-spacingWhy? Template strings give you a readable, concise syntax with proper newlines and string interpolation features.
6.5 Do not unnecessarily escape characters in strings. eslint:
no-useless-escapeWhy? Backslashes harm readability, thus they should only be present when necessary.
Functions
7.1 Use named function expressions instead of function declarations. eslint:
func-style,func-namesWhy? Function declarations are hoisted, which means that it’s easy - too easy - to reference the function before it is defined in the file. This harms readability and maintainability. If you find that a function’s definition is large or complex enough that it is interfering with understanding the rest of the file, then perhaps it’s time to extract it to its own module! Don’t forget to explicitly name the expression, regardless of whether or not the name is inferred from the containing variable (which is often the case in modern browsers or when using compilers such as Babel). This eliminates any assumptions made about the Error’s call stack. (Discussion)
7.2 Wrap immediately invoked function expressions in parentheses. eslint:
wrap-iifeWhy? An immediately invoked function expression is a single unit - wrapping both it, and its invocation parens, in parens, cleanly expresses this. Note that in a world with modules everywhere, you almost never need an IIFE.
7.3 Never declare a function in a non-function block (
if,while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. eslint:no-loop-func7.4 Note: ECMA-262 defines a
blockas a list of statements. A function declaration is not a statement.7.5 Never name a parameter
arguments. This will take precedence over theargumentsobject that is given to every function scope.7.6 Never use
arguments, opt to use rest syntax...instead. eslint:prefer-rest-paramsWhy?
...is explicit about which arguments you want pulled. Plus, rest arguments are a real Array, and not merely Array-like likearguments.7.7 Use default parameter syntax rather than mutating function arguments.
7.8 Avoid side effects with default parameters.
Why? They are confusing to reason about.
7.9 Always put default parameters last. eslint:
default-param-last7.10 Never use the Function constructor to create a new function. eslint:
no-new-funcWhy? Creating a function in this way evaluates a string similarly to
eval(), which opens vulnerabilities.7.11 Spacing in a function signature. eslint:
space-before-function-parenspace-before-blocksWhy? Consistency is good, and you shouldn’t have to add or remove a space when adding or removing a name.
7.12 Never mutate parameters. eslint:
no-param-reassignWhy? Manipulating objects passed in as parameters can cause unwanted variable side effects in the original caller.
7.13 Never reassign parameters. eslint:
no-param-reassignWhy? Reassigning parameters can lead to unexpected behavior, especially when accessing the
argumentsobject. It can also cause optimization issues, especially in V8.7.14 Prefer the use of the spread syntax
...to call variadic functions. eslint:prefer-spreadWhy? It’s cleaner, you don’t need to supply a context, and you can not easily compose
newwithapply.7.15 Functions with multiline signatures, or invocations, should be indented just like every other multiline list in this guide: with each item on a line by itself, with a trailing comma on the last item. eslint:
function-paren-newline
Arrow Functions
8.1 When you must use an anonymous function (as when passing an inline callback), use arrow function notation. eslint:
prefer-arrow-callback,arrow-spacingWhy? It creates a version of the function that executes in the context of
this, which is usually what you want, and is a more concise syntax.Why not? If you have a fairly complicated function, you might move that logic out into its own named function expression.
8.2 If the function body consists of a single statement returning an expression without side effects, omit the braces and use the implicit return. Otherwise, keep the braces and use a
returnstatement. eslint:arrow-parens,arrow-body-styleWhy? Syntactic sugar. It reads well when multiple functions are chained together.
8.3 In case the expression spans over multiple lines, wrap it in parentheses for better readability.
Why? It shows clearly where the function starts and ends.
8.4 Always include parentheses around arguments for clarity and consistency. eslint:
arrow-parensWhy? Minimizes diff churn when adding or removing arguments.
8.5 Avoid confusing arrow function syntax (
=>) with comparison operators (<=,>=). eslint:no-confusing-arrow8.6 Enforce the location of arrow function bodies with implicit returns. eslint:
implicit-arrow-linebreak
Classes and Constructors
9.1 Always use
class. Avoid manipulatingprototypedirectly.Why?
classsyntax is more concise and easier to reason about.9.2 Use
extendsfor inheritance.Why? It is a built-in way to inherit prototype functionality without breaking
instanceof.9.3 Methods can return
thisto help with method chaining.9.4 It’s okay to write a custom
toString()method, just make sure it works successfully and causes no side effects.9.5 Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. eslint:
no-useless-constructor9.6 Avoid duplicate class members. eslint:
no-dupe-class-membersWhy? Duplicate class member declarations will silently prefer the last one - having duplicates is almost certainly a bug.
9.7 Class methods should use
thisor be made into a static method unless an external library or framework requires using specific non-static methods. Being an instance method should indicate that it behaves differently based on properties of the receiver. eslint:class-methods-use-this9.8 Use the
#notation and syntax for private properties in a class instead of_.The # notation provides true encapsulation by making the variables truly private to the class. They are not accessible from outside the class, not even through inheritance or by using reflection techniques.
Modules
10.1 Always use modules (
import/export) over a non-standard module system. You can always transpile to your preferred module system.Why? Modules are the future, let’s start using the future now.
10.2 Do not use wildcard imports.
Why? This makes sure you have a single default export.
10.3 And do not export directly from an import.
Why? Although the one-liner is concise, having one clear way to import and one clear way to export makes things consistent.
10.4 Only import from a path in one place. eslint:
no-duplicate-importsWhy? Having multiple lines that import from the same path can make code harder to maintain.
10.5 Do not export mutable bindings. eslint:
import/no-mutable-exportsWhy? Mutation should be avoided in general, but in particular when exporting mutable bindings. While this technique may be needed for some special cases, in general, only constant references should be exported.
10.6 In modules with a single export, prefer default export over named export. eslint:
import/prefer-default-exportWhy? To encourage more files that only ever export one thing, which is better for readability and maintainability.
10.7 Put all
imports above non-import statements. eslint:import/firstWhy? Since
imports are hoisted, keeping them all at the top prevents surprising behavior.10.8 Multiline imports should be indented just like multiline array and object literals. eslint:
object-curly-newlineWhy? The curly braces follow the same indentation rules as every other curly brace block in the style guide, as do the trailing commas.
10.9 Disallow Webpack loader syntax in module import statements. eslint:
import/no-webpack-loader-syntaxWhy? Since using Webpack syntax in the imports couples the code to a module bundler. Prefer using the loader syntax in
webpack.config.js.10.10 Do not include JavaScript filename extensions eslint:
import/extensionsWhy? Including extensions inhibits refactoring, and inappropriately hardcodes implementation details of the module you're importing in every consumer.
Iterators and Generators
11.1 Don’t use iterators. Prefer JavaScript’s higher-order functions instead of loops like
for-inorfor-of. eslint:no-iteratorno-restricted-syntaxWhy? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects.
Use
map()/every()/filter()/find()/findIndex()/reduce()/some()/ ... to iterate over arrays, andObject.keys()/Object.values()/Object.entries()to produce arrays so you can iterate over objects.11.2 Don’t use generators for now.
Why? They don’t transpile well to ES5.
11.3 If you must use generators, or if you disregard our advice, make sure their function signature is spaced properly. eslint:
generator-star-spacingWhy?
functionand*are part of the same conceptual keyword -*is not a modifier forfunction,function*is a unique construct, different fromfunction.
Properties
12.1 Use dot notation when accessing properties. eslint:
dot-notation12.2 Use bracket notation
[]when accessing properties with a variable.12.3 Use exponentiation operator
**when calculating exponentiations. eslint:prefer-exponentiation-operator.
Variables
13.1 Always use
constorletto declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that. eslint:no-undefprefer-const13.2 Use one
constorletdeclaration per variable or assignment. eslint:one-varWhy? It’s easier to add new variable declarations this way, and you never have to worry about swapping out a
;for a,or introducing punctuation-only diffs. You can also step through each declaration with the debugger, instead of jumping through all of them at once.13.3 Group all your
consts and then group all yourlets.Why? This is helpful when later on you might need to assign a variable depending on one of the previously assigned variables.
13.4 Assign variables where you need them, but place them in a reasonable place.
Why?
letandconstare block scoped and not function scoped.13.5 Don’t chain variable assignments. eslint:
no-multi-assignWhy? Chaining variable assignments creates implicit global variables.
13.6 Avoid using unary increments and decrements (
++,--). eslintno-plusplusWhy? Per the eslint documentation, unary increment and decrement statements are subject to automatic semicolon insertion and can cause silent errors with incrementing or decrementing values within an application. It is also more expressive to mutate your values with statements like
num += 1instead ofnum++ornum ++. Disallowing unary increment and decrement statements also prevents you from pre-incrementing/pre-decrementing values unintentionally which can also cause unexpected behavior in your programs.13.7 Avoid linebreaks before or after
=in an assignment. If your assignment violatesmax-len, surround the value in parens. eslintoperator-linebreak.Why? Linebreaks surrounding
=can obfuscate the value of an assignment.13.8 Disallow unused variables. eslint:
no-unused-varsWhy? Variables that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring. Such variables take up space in the code and can lead to confusion by readers.
Hoisting
14.1
vardeclarations get hoisted to the top of their closest enclosing function scope, their assignment does not.constandletdeclarations are blessed with a new concept called Temporal Dead Zones (TDZ). It’s important to know why typeof is no longer safe.14.2 Anonymous function expressions hoist their variable name, but not the function assignment.
14.3 Named function expressions hoist the variable name, not the function name or the function body.
14.4 Function declarations hoist their name and the function body.
14.5 Variables, classes, and functions should be defined before they can be used. eslint:
no-use-before-defineWhy? When variables, classes, or functions are declared after being used, it can harm readability since a reader won't know what a thing that's referenced is. It's much clearer for a reader to first encounter the source of a thing (whether imported from another module, or defined in the file) before encountering a use of the thing.
For more information refer to JavaScript Scoping & Hoisting by Ben Cherry.
Comparison Operators and Equality
15.2 Conditional statements such as the
ifstatement evaluate their expression using coercion with theToBooleanabstract method and always follow these simple rules:Objects evaluate to true
Undefined evaluates to false
Null evaluates to false
Booleans evaluate to the value of the boolean
Numbers evaluate to false if +0, -0, or NaN, otherwise true
Strings evaluate to false if an empty string
'', otherwise true
15.3 Use shortcuts for booleans, but explicit comparisons for strings and numbers.
15.4 For more information see Truth, Equality, and JavaScript by Angus Croll.
15.5 Use braces to create blocks in
caseanddefaultclauses that contain lexical declarations (e.g.let,const,function, andclass). eslint:no-case-declarationsWhy? Lexical declarations are visible in the entire
switchblock but only get initialized when assigned, which only happens when itscaseis reached. This causes problems when multiplecaseclauses attempt to define the same thing.15.6 Ternaries should not be nested and generally be single line expressions. eslint:
no-nested-ternary15.7 Avoid unneeded ternary statements. eslint:
no-unneeded-ternary15.8 When mixing operators, enclose them in parentheses. The only exception is the standard arithmetic operators:
+,-, and**since their precedence is broadly understood. We recommend enclosing/and*in parentheses because their precedence can be ambiguous when they are mixed. eslint:no-mixed-operatorsWhy? This improves readability and clarifies the developer’s intention.
15.9 The nullish coalescing operator (
??) is a logical operator that returns its right-hand side operand when its left-hand side operand isnullorundefined. Otherwise, it returns the left-hand side operand.Why? It provides precision by distinguishing null/undefined from other falsy values, enhancing code clarity and predictability.
Blocks
16.1 Use braces with all multiline blocks. eslint:
nonblock-statement-body-position16.2 If you’re using multiline blocks with
ifandelse, putelseon the same line as yourifblock’s closing brace. eslint:brace-style16.3 If an
ifblock always executes areturnstatement, the subsequentelseblock is unnecessary. Areturnin anelse ifblock following anifblock that contains areturncan be separated into multipleifblocks. eslint:no-else-return
Control Statements
17.1 In case your control statement (
if,whileetc.) gets too long or exceeds the maximum line length, each (grouped) condition could be put into a new line. The logical operator should begin the line.Why? Requiring operators at the beginning of the line keeps the operators aligned and follows a pattern similar to method chaining. This also improves readability by making it easier to visually follow complex logic.
17.2 Don't use selection operators in place of control statements.
Comments
18.1 Use
/** ... */for multiline comments.18.2 Use
//for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment unless it’s on the first line of a block.18.3 Start all comments with a space to make it easier to read. eslint:
spaced-comment18.4 Prefixing your comments with
FIXMEorTODOhelps other developers quickly understand if you’re pointing out a problem that needs to be revisited, or if you’re suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions areFIXME: -- need to figure this outorTODO: -- need to implement.18.5 Use
// FIXME:to annotate problems.18.6 Use
// TODO:to annotate solutions to problems.
Whitespace
19.2 Place 1 space before the leading brace. eslint:
space-before-blocks19.3 Place 1 space before the opening parenthesis in control statements (
if,whileetc.). Place no space between the argument list and the function name in function calls and declarations. eslint:keyword-spacing19.4 Set off operators with spaces. eslint:
space-infix-ops19.6 Use indentation when making long method chains (more than 2 method chains). Use a leading dot, which emphasizes that the line is a method call, not a new statement. eslint:
newline-per-chained-callno-whitespace-before-property19.7 Leave a blank line after blocks and before the next statement.
19.8 Do not pad your blocks with blank lines. eslint:
padded-blocks19.9 Do not use multiple blank lines to pad your code. eslint:
no-multiple-empty-lines19.10 Do not add spaces inside parentheses. eslint:
space-in-parens19.11 Do not add spaces inside brackets. eslint:
array-bracket-spacing19.12 Add spaces inside curly braces. eslint:
object-curly-spacing19.14 Require consistent spacing inside an open block token and the next token on the same line. This rule also enforces consistent spacing inside a close block token and previous token on the same line. eslint:
block-spacing19.15 Avoid spaces before commas and require a space after commas. eslint:
comma-spacing19.16 Enforce spacing inside of computed property brackets. eslint:
computed-property-spacing19.17 Avoid spaces between functions and their invocations. eslint:
func-call-spacing19.18 Enforce spacing between keys and values in object literal properties. eslint:
key-spacing19.19 Avoid trailing spaces at the end of lines. eslint:
no-trailing-spaces19.20 Avoid multiple empty lines, only allow one newline at the end of files, and avoid a newline at the beginning of files. eslint:
no-multiple-empty-lines
Commas
20.1 Leading commas: Nope. eslint:
comma-style20.2 Additional trailing comma: Yup. eslint:
comma-dangleWhy? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don’t have to worry about the trailing comma problem in legacy browsers.
Semicolons
Why? When JavaScript encounters a line break without a semicolon, it uses a set of rules called Automatic Semicolon Insertion to determine whether it should regard that line break as the end of a statement, and (as the name implies) place a semicolon into your code before the line break if it thinks so. ASI contains a few eccentric behaviors, though, and your code will break if JavaScript misinterprets your line break. These rules will become more complicated as new features become a part of JavaScript. Explicitly terminating your statements and configuring your linter to catch missing semicolons will help prevent you from encountering issues.
Type Casting and Coercion
22.1 Perform type coercion at the beginning of the statement.
22.2 Strings: eslint:
no-new-wrappers22.3 Numbers: Use
Numberfor type casting andparseIntalways with a radix for parsing strings. eslint:radixno-new-wrappersWhy? The
parseIntfunction produces an integer value dictated by interpretation of the contents of the string argument according to the specified radix. Leading whitespace in string is ignored. If radix isundefinedor0, it is assumed to be10except when the number begins with the character pairs0xor0X, in which case a radix of 16 is assumed. This differs from ECMAScript 3, which merely discouraged (but allowed) octal interpretation. Many implementations have not adopted this behavior as of 2013. And, because older browsers must be supported, always specify a radix.22.4 If for whatever reason you are doing something wild and
parseIntis your bottleneck and need to use Bitshift for performance reasons, leave a comment explaining why and what you’re doing.22.5 Note: Be careful when using bitshift operations. Numbers are represented as 64-bit values, but bitshift operations always return a 32-bit integer (source). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. Discussion. Largest signed 32-bit Int is 2,147,483,647:
22.6 Booleans: eslint:
no-new-wrappers
Naming Conventions
23.4 Do not use trailing or leading underscores. eslint:
no-underscore-dangleWhy? JavaScript does not have the concept of privacy in terms of properties or methods. Although a leading underscore is a common convention to mean “private”, in fact, these properties are fully public, and as such, are part of your public API contract. This convention might lead developers to wrongly think that a change won’t count as breaking, or that tests aren’t needed. tl;dr: if you want something to be “private”, it must not be observably present.
23.5 Don’t save references to
this. Use arrow functions or Function#bind.23.6 A base filename should exactly match the name of its default export.
23.7 Use camelCase when you export-default a function. Your filename should be identical to your function’s name.
23.8 Use PascalCase when you export a constructor / class / singleton / function library / bare object.
23.9 Acronyms and initialisms should always be all uppercased, or all lowercased.
Why? Names are for readability, not to appease a computer algorithm.
23.10 You may optionally uppercase a constant only if it (1) is exported, (2) is a
const(it can not be reassigned), and (3) the programmer can trust it (and its nested properties) to never change.Why? This is an additional tool to assist in situations where the programmer would be unsure if a variable might ever change. UPPERCASE_VARIABLES are letting the programmer know that they can trust the variable (and its properties) not to change.
What about all
constvariables? - This is unnecessary, so uppercasing should not be used for constants within a file. It should be used for exported constants however.What about exported objects? - Uppercase at the top level of export (e.g.
EXPORTED_OBJECT.key) and maintain that all nested properties do not change.
Accessors
24.1 Accessor functions for properties are not required.
24.2 Do not use JavaScript getters/setters as they cause unexpected side effects and are harder to test, maintain, and reason about. Instead, if you do make accessor functions, use
getVal()andsetVal('hello').24.3 If the property/method is a
boolean, useisVal()orhasVal().24.4 It’s okay to create
get()andset()functions, but be consistent.
Events
25.1 When attaching data payloads to events (whether DOM events or something more proprietary like Backbone events), pass an object literal (also known as a "hash") instead of a raw value. This allows a subsequent contributor to add more data to the event payload without finding and updating every handler for the event. For example, instead of:
prefer:
jQuery
26.1 Prefix jQuery object variables with a
$.26.2 Cache jQuery lookups.
26.4 Use
findwith scoped jQuery object queries.
ECMAScript 5 Compatibility
27.1 Refer to Kangax’s ES5 compatibility table.
ECMAScript 6+ (ES 2015+) Styles
28.1 This is a collection of links to the various ES6+ features.
28.2 Do not use TC39 proposals that have not reached stage 3.
Why? They are not finalized, and they are subject to change or to be withdrawn entirely. We want to use JavaScript, and proposals are not JavaScript yet.
Standard Library
The Standard Library contains utilities that are functionally broken but remain for legacy reasons.
29.1 Use
Number.isNaNinstead of globalisNaN. eslint:no-restricted-globalsWhy? The global
isNaNcoerces non-numbers to numbers, returning true for anything that coerces to NaN. If this behavior is desired, make it explicit.29.2 Use
Number.isFiniteinstead of globalisFinite. eslint:no-restricted-globalsWhy? The global
isFinitecoerces non-numbers to numbers, returning true for anything that coerces to a finite number. If this behavior is desired, make it explicit.
Testing
30.1 Yup.
30.2 No, but seriously:
Whichever testing framework you use, you should be writing tests!
Strive to write many small pure functions, and minimize where mutations occur.
Be cautious about stubs and mocks - they can make your tests more brittle.
100% test coverage is a good goal to strive for, even if it’s not always practical to reach it.
Whenever you fix a bug, write a regression test. A bug fixed without a regression test is almost certainly going to break again in the future.
Performance
Loading...
Resources
Learning ES6+
Read This
Tools
Code Style Linters
Neutrino Preset - @neutrinojs/airbnb
Other Style Guides
Other Styles
Naming this in nested functions - Christian Johansen
Conditional Callbacks - Ross Allen
Popular JavaScript Coding Conventions on GitHub - JeongHoon Byun
Last updated