| name | javascript |
| description | Google's official JavaScript style guide for ES6+. Covers const/let, arrow functions, template literals, destructuring, modules, naming conventions, JSDoc, and formatting. Enforces modern JavaScript patterns and best practices. |
Google JavaScript Style Guide
Official Google JavaScript coding standards for ES6+ code.
Golden Rules
- Use
const by default — let only when reassignment needed, never var
- Arrow functions for callbacks — traditional functions for methods
- Template literals for string interpolation
- Destructuring where it improves readability
- Named exports over default exports
- JSDoc for public APIs — document parameters and return types
- 2-space indentation — consistent formatting
Quick Reference
Naming Conventions
| Element | Convention | Example |
|---|
| Classes | UpperCamelCase | UserService |
| Functions/Methods | lowerCamelCase | getUserById |
| Variables | lowerCamelCase | userCount |
| Constants | UPPER_SNAKE_CASE | MAX_SIZE |
| Private fields | #privateField | #userId |
| Files | lower-kebab-case | user-service.js |
Variables
const greeting = 'Hello';
let count = 0;
var greeting = 'Hello';
Functions
const double = (x) => x * 2;
array.map(item => item.id);
class User {
getName() {
return this.name;
}
}
function greet(name, greeting = 'Hello') {
return `${greeting}, ${name}!`;
}
Strings
const name = 'Alice';
const greeting = `Hello, ${name}!`;
const greeting = 'Hello, ' + name + '!';
Destructuring
const {id, name} = user;
const {x, y, ...rest} = coordinates;
const [first, second] = items;
const [head, ...tail] = list;
function processUser({id, name, email}) {
}
Modules
export function myFunction() { }
export class MyClass { }
import {myFunction, MyClass} from './my-module.js';
export default function() { }
Classes
class Animal {
#name;
constructor(name) {
this.#name = name;
}
speak() {
return `${this.#name} makes a sound.`;
}
}
JSDoc
function fetchUser(userId, {timeout = 5000} = {}) {
}
Promises and Async/Await
async function fetchUser(id) {
const response = await fetch(`/api/users/${id}`);
if (!response.ok) {
throw new Error(`HTTP error: ${response.status}`);
}
return response.json();
}
try {
const user = await fetchUser(1);
} catch (error) {
console.error('Failed to fetch user:', error);
}
Common Mistakes
| Mistake | Correct Approach |
|---|
Using var | Use const / let |
| String concatenation | Use template literals |
| Default exports | Use named exports |
| Missing JSDoc | Document public APIs |
| Traditional functions for callbacks | Use arrow functions |
| Ignoring destructuring | Use where it helps readability |
When to Use This Guide
- Writing new JavaScript code
- Refactoring existing JavaScript
- Code reviews
- Setting up ESLint rules
- Onboarding new team members
Install
npx skills add testdino-hq/google-styleguides-skills/javascript
Full Guide
See javascript.md for complete details, examples, and edge cases.