background preloader

Guides de Style JavaScript

Facebook Twitter

Ryanmcdermott/clean-code-javascript: Clean Code concepts adapted for JavaScript. Airbnb/javascript: JavaScript Style Guide. Google JavaScript Style Guide. 1 Introduction This document serves as the complete definition of Google’s coding standards for source code in the JavaScript programming language.

Google JavaScript Style Guide

A JavaScript source file is described as being in Google Style if and only if it adheres to the rules herein. Like other programming style guides, the issues covered span not only aesthetic issues of formatting, but other types of conventions or coding standards as well. However, this document focuses primarily on the hard-and-fast rules that we follow universally, and avoids giving advice that isn't clearly enforceable (whether by human or tool). 1.1 Terminology notes In this document, unless otherwise clarified: The term comment always refers to implementation comments. Other terminology notes will appear occasionally throughout the document. 1.2 Guide notes Example code in this document is non-normative. 2 Source file basics 2.1 File name 2.2 File encoding: UTF-8 Source files are encoded in UTF-8. 2.3 Special characters 2.3.1 Whitespace characters. Udacity Nanodegree Style Guide. General Meta Rules Encoding Use UTF-8 (no BOM).

Udacity Nanodegree Style Guide

Make sure your editor uses UTF-8 as character encoding, without a byte order mark. Comments Use comments to explain code: What does it cover, what purpose does it serve, and why is the respective solution used or preferred? You can optionally document your JavaScript functions with JSDoc, a documentation generator and standard for writing code comments. @constructor: used to document a class, a.k.a. a function meant to be called with the new keyword. This example shows how to document a class constructor (note the use of /** to start the comment block; that's important): /** * @description Represents a book * @constructor * @param {string} title - The title of the book * @param {string} author - The author of the book */ function Book(title, author) { ... } Standard/standard: □ JavaScript Style Guide, with linter & automatic code fixer. JavaScript Best Practices.

Writing a best practice article is quite a tricky business.

JavaScript Best Practices

To a number of you, what you are about to read will appear to be very obvious and just the sensible thing to do. However, looking around the web and getting code handed over to me from other developers for years has taught me that common sense is actually quite a rarity in live code on the web, and the “sensible and logical thing to do” gets pushed far down the priority list once you are in the middle of a project, and the deadline is looming. So I’ve decided to make it easier for you by creating this article, which is a compilation of best practices and good advice I’ve amassed over the years, much of it learnt the hard way (experimentation and suchlike). Take the advice below to heart and keep it in a part of your brain that has a quick access route so you can apply it without thinking about it.

The article is structured as follows: Call things by their name — easy, short and readable variable and function names Avoid globals. JavaScript Style Guide. Use JSHint to detect errors and potential problems.

JavaScript Style Guide

Every jQuery project has a Grunt task for linting all JavaScript files: grunt jshint. The options for JSHint are stored in a .jshintrc file; many repositories will have multiple .jshintrc files based on the type of code in each directory. Each .jshintrc file follows a specific format. All options must be alphabetized and grouped: The following common options must be used in all projects: If the project supports browsers which do not implement ES5, then the es3 option must be included with the repo-specific options.

In general, the jQuery style guide encourages liberal spacing for improved human readability. Indentation with tabs.No whitespace at the end of line or on blank lines.Lines should be no longer than 80 characters, and must not exceed 100 (counting tabs as 4 spaces). Object and array expressions can be on one line if they are short (remember the line length limits). Airbnb/javascript: JavaScript Style Guide. Google JavaScript Style Guide. Translations/fr_FR at master · rwaldron/idiomatic.js. Standard/standard: □ JavaScript Style Guide, with linter & automatic code fixer.

5 JavaScript Style Guides — Including AirBnB, GitHub, & Google.