Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
J

javascript

> 开发工具
Open source

JavaScript Style Guide

148.1K stars0 likes4 views
WebsiteGitHub

About

JavaScript Style Guide

Airbnb JavaScript Style Guide() {

A mostly reasonable approach to JavaScript

Note: this guide assumes you are using Babel, and requires that you use babel-preset-airbnb or the equivalent. It also assumes you are installing shims/polyfills in your app, with airbnb-browser-shims or the equivalent.

This guide is available in other languages too. See Translation

Other Style Guides

  • ES5 (Deprecated)
  • React
  • CSS-in-JavaScript
  • CSS & Sass
  • Ruby Table of Contents
  1. Types
  2. References
  3. Objects
  4. Arrays
  5. Destructuring
  6. Strings
  7. Functions
  8. Arrow Functions
  9. Classes & Constructors
  10. Modules
  11. Iterators and Generators
  12. Properties
  13. Variables
  14. Hoisting
  15. Comparison Operators & Equality
  16. Blocks
  17. Control Statements
  18. Comments
  19. Whitespace
  20. Commas
  21. Semicolons
  22. Type Casting & Coercion
  23. Naming Conventions
  24. Accessors
  25. Events
  26. jQuery
  27. ECMAScript 5 Compatibility
  28. ECMAScript 6+ (ES 2015+) Styles
  29. Standard Library
  30. Testing
  31. Performance
  32. Resources
  33. In the Wild
  34. Translation
  35. The JavaScript Style Guide Guide
  36. Chat With Us About JavaScript
  37. Contributors
  38. License
  39. Amendments Types

  • 1.1 Primitives: When you access a primitive type you work directly on its value.

    • string
    • number
    • boolean
    • null
    • undefined
    • symbol
    • bigint

    • Symbols and BigInts cannot be faithfully polyfilled, so they should not be used when targeting browsers/environments that don’t support them natively.

  • 1.2 Complex: When you access a complex type you work on a reference to its value.

    • object
    • array
    • function

⬆ back to top References

  • 2.1 Use const for all of your references; avoid using var. eslint: prefer-const, no-const-assign

    Why? This ensures that you can’t reassign your references, which can lead to bugs and difficult to comprehend code.

  • 2.2 If you must reassign references, use let instead of var. eslint: no-var

    Why? let is block-scoped rather than function-scoped like var.

  • 2.3 Note that both let and const are block-scoped, whereas var is function-scoped.

    In the above code, you can see that referencing a and b will produce a ReferenceError, while c contains the number. This is because a and b are block scoped, while c is scoped to the containing function.

⬆ back to top Objects

  • 3.1 Use the literal syntax for object creation. eslint: no-new-object

  • 3.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-shorthand

  • 3.4 Use property value shorthand. eslint: object-shorthand

    Why? 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-props

    Why? 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.prototype methods directly, such as hasOwnProperty, propertyIsEnumerable, and isPrototypeOf. eslint: no-prototype-builtins

    Why? 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:/

Issues· 167 open

View all issuesOpen on GitHub
  • #3237

    Severity: Unhandled promise rejection in `whitespace-async.js` when ESLint async path is used

    Updated Sep 8, 2026
  • #3173

    Can we publish eslint-config-airbnb v19.0.5 please?

    Updated Jul 14, 2026
  • #3152

    Inconsistent semicolon usage in examples (Arrays vs Functions)

    Updated Jun 26, 2026
  • #685

    Lint the readme

    enhancementpull request wantedUpdated Apr 23, 2026
  • #2804

    Support of new eslint flat config

    Updated Apr 15, 2026
  • #3121

    Discussion: Arrow Functions vs Traditional Functions

    questionUpdated Mar 31, 2026
  • #3238

    No error handling around execSync + JSON.parse in whitespace.js (ESLint 9 path)

    Updated Mar 6, 2026
  • #3186

    Upgrading eslint-plugin-react-hooks

    Updated Jan 6, 2026
  • #2208

    What is the point of the "Types" section of the guide?

    questionUpdated Dec 13, 2025
  • #3069

    [eslint-config-airbnb] `jsx-a11y/control-has-associated-label` config does not ignore `td` and `th` HTML elements

    pull request wantedUpdated Dec 4, 2025

> Tags

JavaScriptarrow-functionses2015es2016es2017

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 2, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具