JavaScript Conventions - GeoSmartCity-CIP/gsc GitHub Wiki
For example:
firstName = "John";
lastName = "Doe";
price = 19.90;
tax = 0.20;
fullPrice = price + (price * tax);
Spaces Around Operators:
Always put spaces around operators ( = + - * / ), and after commas. For Example:
var x = y + z;
var values = ["Volvo", "Saab", "Fiat"];
Code Indentation:
Always use 4 spaces for indentation of code blocks.
Statement Rules:
Always end a simple statement with a semicolon. For example:
var values = ["Volvo", "Saab", "Fiat"];
General rules for complex (compound) statements:
- Put the opening bracket at the end of the first line.
- Use one space before the opening bracket.
- Put the closing bracket on a new line, without leading spaces.
- Do not end a complex statement with a semicolon.
Line Length < 80
For readability, avoid lines longer than 80 characters.
If a JavaScript statement does not fit on one line, the best place to break it, is after an operator or a comma.