Coding Standard - Mits10/School_Management_System_Php_Html_Css_JavaScript_From_Scratch GitHub Wiki
Coding Standards: JavaScript
Naming Conventions:
Variable Name:
Variable names should be in camelCase for identifier names. All names start with a letter.
Example:
firstName = "Anusha";
lastName = "Mehrin";
Global Variable Name:
Global variable names should also be in camelCase.
Example:
var value=100;
Function Name:
Function names are declared with function keyword, followed by a name which should be written in camelCase.
Example:
function myFunction(a, b)
{
return a * b;
}
Constant Name:
Constant names should be written in camelCase.
Example:
const userAge = 30;
Class Name:
Class Names should be written in PascalCase.
Example:
Class UserStory {…..}
Indentation:
4-space indentation should be used.
Example:
function myFunction(a, b)
{
....return a * b;
}
Line Length:
Line length should be less than 80. If a statement does not fit on one line, it should be broken after an operator or a comma.
Module Name:
Module names should be written in lower case. Multiple words should be written in camelCase.
Example:
modules/ canvas.js square.js
Exception Name:
Exception Names should be written in PascalCase.
Spaces Around Operators:
Spaces should be put around operators and commas.
Example:
var a = b + c;
Statement Rules for simple statements:
Simple statements should preferrably end with semicolon.
Example:
var values = ["Apple", "Orange", "Mango"];
General rules for complex statements:
- 
Opening bracket should be put at the end of the first line. 
- 
One space should be used before the opening bracket. 
- 
Closing bracket on a new line should be put without leading spaces. 
- 
Complex statements should not end with a semicolon. 
General rules for object definitions:
- 
Opening bracket should be put on the same line as the object name. 
- 
Colon plus one space should be used between each property and its value. 
- 
Quotes should be put around string values, not around numeric values. 
- 
Comma should not be added after the last property-value pair. 
- 
Closing bracket should be put on a new line without leading spaces. 
- 
Object definition should always end with a semicolon. 
Example:
var course =
{
courseName: "Software Engineering",
courseCode: "CSE327",
credit: 3
};