IjasSept. 18, 2019
With two decades of improvement, JavaScript has become one of the most popular programming languages of all time. This blogs describes the javaScript coding convention and rules for use in JavaScript programming.
The long-term value of software to an organization is in direct proportion to the quality of the codebase. Over its lifetime, a program will be handled by many pairs of hands and eyes. If a program is able to clearly communicate its structure and characteristics, it is less likely that it will break when modified in the never-too-distant future. JavaScript coding convention can help in reducing the brittleness of programs. They are style guidelines for programming. They typically cover naming and also declaration rules for variables and functions. Rules for the use of white space,indentation ,and comments, programming practices and principles. It improves code readability and make code maintenance easier.
Always use the same coding convention for all your JavaScript projects. The javaScript coding convention secure quality. They are style guidelines for programming.
JavaScript programs should be store in and deliver as .js files. The JavaScript code should not be embed in HTML files unless the code is specific to a single session.
All variables should be declare before use. JavaScript does not require this, but doing so makes the program easier to read and makes it easier to detect undeclared variables that may become implied. Implied global variables should never be used. Use of global variables should be minimized.
Blank lines improve readability by setting off sections of code that are logically related. Blank spaces should always be use in the following circumstances:
Be generous with comments. It is useful to leave information that will be read at a later time by people (possibly your future self) who will need to understand what you have done and why. The comments should be well-written and clear
It is important that comments be keep up-to-date. Make comments meaningful.
All functions should be declare before they are used. Inner functions should come after the outer function's variable declarations. This helps in making it clear what variables will be include in its scope.
There should be no space between the name of a function and the (left parenthesis of its parameter list. There should be one space between the )right parenthesis and the {left curly brace that begins the statement body. The body itself is indent four spaces. The }right curly brace is align with the line containing the beginning of the declaration of the function.
Each line should contain at most one statement. Put a ;semicolon at the end of every statement that does not end with a {block}. Note that an assignment statement that is assigning a function literal or object literal is still an assignment statement and must end with a semicolon.
Compound statements are statements that contain lists of statements enclosed in { }curly braces.
A if statement should have one of these forms:
if (condition) { statements } if (condition) { statements } else { statements } if (condition) { statements } else if (condition) { statements } else { statements }
When the for statement is in use, it should one of these forms:
for (initialization; condition; update) { statements } for ( initialization; condition; update ) { statements }
A while statement should have the following form:
while (condition) { statements }
A do statement should have this form:
do { statements } while (condition);
Unlike the other compound statements, the do statement always ends with a ;semicolon.
A switch statement should be avoid, but when in use should have this form:
switch (expression) { case expression: statements default: statements }
The try statement should have this form:
try { statements } catch (variable) { statements }
Use simple syntax for loading external scripts :
<script src="myscript.js"></script>
In the above blog, we explain about JavaScript and its Coding Convention and how it is facilitated in Technaureus Info Solutions Pvt.Ltd.
0