This document describes the core JavaScript style guide for the Airbnb JavaScript Style Guide repository, as documented in README.md1-4098 The guide defines fundamental language patterns, syntax conventions, and best practices for writing modern JavaScript (ES6+). It assumes the use of Babel transpilation via babel-preset-airbnb and browser polyfills via airbnb-browser-shims README.md5-6
For details on specific topics, see the following child pages:
Sources: README.md1-10
The JavaScript style guide is organized into 30 major sections covering language fundamentals through testing and performance considerations README.md21-61 The core rules are enforced via ESLint configurations in eslint-config-airbnb and eslint-config-airbnb-base packages.
The following diagram maps high-level style categories to the specific code entities and rules that govern them.
Sources: README.md21-61 README.md63-3820
JavaScript distinguishes between primitive types like string, number, and boolean (pass-by-value) and complex types like object and array (pass-by-reference) README.md65-105 The guide mandates const for all references to ensure they cannot be reassigned, and let only when reassignment is necessary, strictly prohibiting var due to its function-scoping behavior README.md111-143
For details, see Types, Variables, and References.
Sources: README.md63-162
The guide enforces literal syntax for objects and arrays ({} and []), discouraging the use of constructors like new Object() README.md166-174 It promotes modern ES6+ features such as computed property names, object method shorthand, and the spread operator for creating shallow copies README.md178-224 Destructuring is required when accessing and using multiple properties of an object or array README.md468-477
For details, see Objects, Arrays, and Destructuring.
Sources: README.md164-576
Single quotes (') are the standard for strings README.md580-588 Template literals (backticks) are required when programmatically building strings or for multi-line strings to avoid manual concatenation README.md611-628
For details, see Strings and Template Literals.
Sources: README.md578-659
The guide prioritizes named function expressions over function declarations to prevent hoisting issues README.md663-688 Arrow functions are required for anonymous callbacks and situations requiring lexical this README.md884-904
For details, see Functions and Arrow Functions.
Sources: README.md661-1107
ES6 class syntax is mandatory over direct prototype manipulation README.md1111-1118 The module system relies on import/export syntax rather than non-standard module systems README.md1240-1248 Functional iteration methods like map(), every(), and reduce() are preferred over for-in or for-of loops to emphasize immutable data patterns README.md1396-1415
For details, see Classes, Modules, and Iterators.
Sources: README.md1109-1591
Strict equality (===) is required over abstract equality (==) README.md2024-2035 The guide provides specific truthiness rules for booleans and dictates the structure of blocks, including "cuddled" else statements and mandatory braces for all control statements README.md2250-2270
For details, see Comparison Operators and Control Flow.
Sources: README.md2022-2419
This covers the visual consistency of the codebase: 2-space indentation, 100-character line limits, mandatory semicolons, and trailing commas README.md2618-3162 It also defines naming conventions like camelCase for variables/functions and PascalCase for classes/constructors README.md3300-3340
For details, see Code Style and Formatting.
Sources: README.md2562-3575
The style guide is implemented through a series of ESLint rules defined in the configuration packages.
The following diagram bridges natural language style requirements to the specific ESLint rules used in the codebase to enforce them.
Sources: README.md112 README.md127 README.md167 README.md2024
The guide extends to the usage of the JavaScript standard library and testing practices:
Number.isNaN() over the global isNaN() and Number.isFinite() over global isFinite() for more reliable type checking README.md3781-3819Sources: README.md3781-3841
Refresh this wiki