Airbnb JavaScript Style Guide: Coding Conventions
Airbnb JavaScript Style Guide is a set of JavaScript coding conventions Airbnb publishes with a matching ESLint rule for almost every guideline. Reach for it for a documented, lint-enforceable baseline on const/let, object and array literals, destructuring, and strings instead of relitigating style in every pull request. Skip it if your team already has a working convention, like Standard, and doesn't want to redo tooling to match a different one.
Understanding the Airbnb JavaScript Style Guide
Airbnb JavaScript Style Guide is a public reference of JavaScript coding conventions in the airbnb/javascript GitHub repository, spanning types, references, objects, arrays, destructuring, strings, and functions. Each guideline pairs a short rationale with bad-versus-good code samples, and many map to a named ESLint rule such as prefer-const or object-shorthand. It assumes Babel and links companion guides for React and CSS-in-JavaScript.
Key Principles and Coding Conventions
- โRequires const for anything not reassigned and let for anything that is, banning var outright and citing the prefer-const and no-var ESLint rules.
- โTreats let and const as block-scoped and var as function-scoped, with a code sample showing the ReferenceError that results from getting this wrong.
- โFavors literal syntax over constructors: {} instead of new Object(), and [] instead of new Array(), each tied to its own ESLint rule.
- โUses object spread ({ ...original, c: 3 }) instead of Object.assign for shallow copies, since Object.assign on an existing object mutates it.
- โRequires object destructuring for accessing multiple properties and for multiple function return values, backed by the prefer-destructuring rule.
- โConverts iterables to arrays with spread (...foo) but switches to Array.from(foo, bar) specifically when mapping, to avoid an intermediate array.
- โStandardizes on single-quoted strings and template literals for concatenation, and bans eval() outright.
- โRequires named function expressions instead of anonymous ones or hoisted declarations, and wraps IIFEs in parentheses per the wrap-iife rule.
Who Benefits From This Style Guide?
Airbnb JavaScript Style Guide suits a team that already uses Babel and ESLint and wants a documented, rule-by-rule baseline instead of writing conventions from scratch. The const/let/var section alone settles a debate most teams handle informally. It's less useful for a solo project or a team happy with its current linter config, since adopting it means reconciling every existing rule against Airbnb's own choices.
Strengths
- โNearly every rule cites the exact ESLint rule name that enforces it: prefer-const, no-array-constructor, prefer-object-spread, quotes, no-eval. That makes it wireable into CI, not just a document to reread.
- โRules show bad, good, and sometimes best code side by side instead of describing the change in prose.
- โMost guidelines include a short 'Why?' explaining the tradeoff, like why destructuring beats repeated property access.
- โCompanion guides for React and CSS-in-JavaScript extend the same conventions into adjacent parts of a typical frontend stack.
- โMIT licensed, so copying rules or the whole document into an internal handbook carries no license friction.
Considerations and Requirements
- โณThe guide assumes a Babel-based build (babel-preset-airbnb or equivalent) plus shim/polyfill packages, so it's not a drop-in reference for a project without that toolchain.
- โณIts table of contents runs to several dozen sections beyond what's covered here (Classes, Modules, Naming Conventions, Comments, and more), so adopting it fully is a bigger lift than the object/array/string rules alone suggest.
- โณIt documents Airbnb's own house style, not a neutral spec, so teams already standardized on a different convention face a rewrite to switch.
- โณNo version number or last-updated date appears in the facts available here, so there's no way to tell how current a given section is from the repo metadata alone.
- โณInstall and everyday usage aren't spelled out as a getting-started section. The README works as a per-rule reference, not a walkthrough of adopting the guide end to end.
Other Popular JavaScript Style Guides
Frequently Asked Questions
Airbnb JavaScript Style Guide targets modern ECMAScript, reflected in repo topics like es2015 through es2018, es6, and tc39, and its rules assume a Babel-compiled build rather than raw ES5 execution.
Airbnb JavaScript Style Guide's README says it assumes Babel and requires babel-preset-airbnb (or an equivalent) plus shims from airbnb-browser-shims, and most rules cite a specific ESLint rule that enforces them.
Airbnb JavaScript Style Guide's repository lists a companion React guide under its Other Style Guides section (react/), meant to extend the same conventions into React-specific code.
Airbnb JavaScript Style Guide is released under the MIT license, according to the airbnb/javascript repository's license metadata.
Airbnb JavaScript Style Guide's README says translations into other languages exist and links out to a dedicated Translation section, though the specific language list isn't detailed in the excerpt reviewed here.
Airbnb JavaScript Style Guide favors block-scoped const and let over var, literal syntax over constructors like new Object() or new Array(), destructuring over repeated property access, and named function expressions over anonymous ones, pairing most rules with a specific ESLint rule.
Best use cases
- โขBootstrapping a new team's ESLint config by adopting Airbnb's named rules (prefer-const, no-var, object-shorthand, quotes) as a starting rule set.
- โขSettling recurring code-review arguments over const/let/var, quote style, or Object.assign versus spread by pointing to a documented, shared rule.
- โขTeaching a developer new to ES6+ syntax using the guide's paired bad/good code examples for destructuring, template literals, and spread.
- โขExtending the same conventions into a React codebase through the companion React guide the repo links under Other Style Guides.
- โขAuditing an existing JavaScript codebase's object, array, and string handling against a documented outside reference instead of team folklore.
Related repositories
Still deciding about javascript?
One click hands the question to an AI along with this page โ see what it says about javascript.
