2.1 KiB
title, last_modified
| title | last_modified |
|---|---|
| Code Styleguide — JavaScript | 2026-02-22 |
-
Use
constfor all declarations, unless you need to reassign, then uselet. Never usevar. -
Indentation: Use 2 spaces. Do not use tabs.
-
Semicolons shoudl be used at the end of statements.
-
Quotes: Prefer single quotes for strings, unless working with JSON or needing to separate object strings.
-
Limit lines to approximately 80 characters for better readability.
-
Brace Placement: Place the opening brace on the same line as the statement (e.g., if (true) {).
-
Naming Conventions:
Variables, properties, and functions use lowerCamelCase. Class names use UpperCamelCase (PascalCase). Constants use UPPERCASE_WITH_UNDERSCORES.
-
Equality: Always use the strict equality operator (===) over the abstract equality operator (==).
-
Use npm for package management, avoid using yarn.
-
Use nvm and install/select the most current LTS Node version.
-
Use
prettierfor code formatting, with four spaces for indentation. -
At a minimum, both
npm run test/npm run buildshould work (complete the appropriate scripts inpackage.json). However, prefermake testandmake buildinstead — -
The Makefile is authoritative on how to interact with the repo. See Repository Policies for details.
-
Use UNIX-style newlines (\n), and a newline character as the last character of a file. Windows-style newlines (\r\n) are forbidden inside any Node/JS repository.
-
Declare one variable per statement:
Correct:
const keys = ['foo', 'bar'];
const values = [23, 42];
const object = {};
Incorrect:
const keys = ['foo', 'bar'],
values = [23, 42],
object = {},
- Name closures in order to produce better stack traces, heap and cpu profiles.
Correct:
req.on('end', function onEnd() {
console.log('winning');
});
Incorrect:
req.on('end', function() {
console.log('losing');
});
Author
License
MIT. See LICENSE.