Skip to content

JavaScript Coding Style Guidelines

korenyushkin edited this page May 22, 2011 · 1 revision

This guide describes the style which should be used in all official Akshell JavaScript libraries.

General

  • When adapting third-party code, stick with its style
  • Line length should not exceed 80 characters
  • Each var declaration should be on a separate line
  • Always use semicolons
  • Prefer ' over "
  • Avoid complex nesting
  • Always comment hacks, but try to avoid them
  • Use == for primitive types
  • Use === for objects
  • Use Akshell goodies in all server code

Spacing

  • Use 2 spaces for indentation
  • Tabs are forbidden
  • Do not use space after a function name
  • Do / Do not use a space after the function keyword if it's anonymous
  • Do not pad parameter lists and functions calls with spaces, except after commas
  • Do use space after if, for, while, function
  • Do surround binary and ternary operators by spaces
  • Do not surround unary operators by spaces
  • Separate module-scope functions by 2 blank lines

Bracing

  • Do not place opening curly braces on a separate line (K&R over Allman)
  • Do not use curly braces in if, else, for, while one-statement blocks
  • Do use curly braces in if and else blocks if the other block has multiple statements

Naming

  • Camel case variable and function names likeThis
  • Camel case class and constructor names LikeThis
  • Upper case constant names LIKE_THIS
  • Names should be descriptive except traditional loop counters (i, j, k)
  • Array variables should have names in plural form

Clone this wiki locally