JavaScript code guidelines


This is the code guidelines for writing JavaScript code for the Friend Workspace. Please adhere to these when submitting new code, or download a code formatter, available elsewhere on these developer pages.

General guidelines

When writing JavaScript code in Friend, please make sure that you go ahead by respecting the following rules:

Make sure to comment each function using at least a single line comment like this:

// This simple function takes an unformatted string and returns a formatted string

Write your function name using UCFirst, uppercase first:

function MySimpleFunction( arg1, arg2 )

Please use logical variable names if the variable does something special:

var someName = 'Some Name'; v.s. var abcd = 'Some Name' (someName is preferred!)

Bracket on newline

Where to place those brackets? The discussion has been going between programmers for a long time. Some prefer on the same line. Some prefer with a newline in front. We have to make a decision, and we chose to have the bracket after a new line like so:

if( theVar == 4 )
    // Do something

Spaces and tabs

It is allowed to use tabs on the beginning of a line, but not after a non space character:

if( here == 'there' )
    // Tabbed - spaced
    // Another tab - space

Also, notice the space after the paranthesis and the variable inside the if. We space our variables and parameters for good readability.

Single versus double quotes

When declaring or comparing strings, we use single quotes. In JavaScript, this may not be a strict routine, though, so the rule of thumb is, if you start by writing a code file with single quotes, be consistent. And as most of the Friend Workspace code uses single quotes, it makes sense to continue doing so.

var myString = 'This is a plain string.';
Was this page helpful?