Search Our Site:    Advanced Search
BCC Home > Web Design Standards > JavaScript Coding Standards

JavaScript Coding Standards

Scope

This documents the coding standards for JavaScript. Java Script is used in Web pages to add interactivity and conditional logic. This document is intended to be a living document. It serves as the vehicle for deriving and documenting agreed to practices by all involved personnel writing JavaScript for the Brevard County Board of County Commissoiners websites.

Intended Audience

This document is intended for website developers in the Brevard County Information Systems Department and interfacing agencies. It is intended for all personnel who wish to develop industry best practices in the development of content for the Brevard County Internet and Intranet Web Sites.

JavaScript Coding Standards

This section outlines the standard guidelines to be followed when using JavaScript. The standards are divided up into separate tables according to functional category.

Naming Conventions

Unlike XHTML, which is not case sensitive, JavaScript is a case sensitive language. In order to decrease the potential for bugs and to increase readability of the code, it is important to maintain consistency in capitalization. Capitalization guidelines need to apply to JavaScript keywords, classes, functions, variables and any other identifiers.

Unlike the Windows operating system, which is not case sensitive, the UNIX operation system is case sensitive. This means that directory and filenames are case sensitive in UNIX. To reduce the chance of error when transferring files between the PC and UNIX platforms, there needs to be a consistency in directory and file naming. Also, avoid spaces in filenames. Spaces cause problems in some backup software.

The names for files, classes, instances and variables and any other identifiers shall all adhere to the following general industry best practice guidelines:

  1. Begin names with a character (lower or uppercase as defined below) or underscore, nothing else. Subsequent characters may be any letter or digit.
  2. Use names that are descriptive
  3. Do not place any spaces in the name

Guidelines unique to a file, directory, class or identifier are outlined in the following table.

Guideline Example Rationale
File names: Use only lowercase. Do not use spaces or underscores. File name: thedeptpicnictour Standardization for consistency in maintaining correct filenames in case sensitive environments.
File structure: Place JavaScript in separate ".js" files. Reference them from the XHTML file used in. Filename: deptpictures.js Readability of base XHTML code.
Class names: Name classes with an initial capital letter. Capitalize each word thereafter. Class name: CircleManipulation Industry best/standard practice.
Class objects: Name the instances (objects) of classes with lower case letters. Capitalize each word thereafter. Class instance name: circleManipulationInstance Industry best/standard practice.
Variables: Start a variable with a lowercase letter and capitalize the first letter of each word thereafter. Variable name: myNumberVariable Maintain consistency in case sensitive environments to reduce errors.

Syntax Conventions

The syntax of a program is the set of rules that must be adhered to in writing the code so that it can be interpreted or compiled properly. The following table depicts guidelines where the syntax may be written in more than one way.

Guideline Example Rationale
Semicolons: Use a semicolon at the end of each statement.

a=3; NOT a=3

b=2; b=3;

JavaScript does not require a semicolon at the end of a statement if it is on its own line. Semicolons should always be used for readability, consistence, and ease in debugging.

Change Record

Date Revision
02/26/2003 Revised file name example for consistency. Deleted code format example under Syntax Conventions.
08/17/2000 Incorporated comments.
08/14/2000 Initial Release. Earl Chassee.
Privacy Policy Adobe Reader download icon Adobe Reader | Flash Player download icon Flash Player | Using Our Site

Contact the Webmaster about this website's content, services or technical issues.

Under Florida law, email addresses are public records. If you do not want your email address released in response to a
public-records request, do not send electronic mail to this entity. Instead, contact this office by phone or in writing.

Brevard County seal The Official Site of Brevard County, Florida

Information Systems Dept., Bldg. GC-206
2725 Judge Fran Jamieson Way
Viera, Fl 32940
Tel: (321) 617-7395