0% found this document useful (0 votes)
10 views

JavaScriptStyle

Js scripts
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

JavaScriptStyle

Js scripts
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

JavaScript Style Guide and

Coding Conventions
https://www.w3schools.com/js/js_conventions.asp

https://www.w3schools.com/js/js_best_practices.asp

JavaScript Coding Conventions


Coding conventions are style guidelines for programming. They typically
cover:

• Naming and declaration rules for variables and functions.


• Rules for the use of white space, indentation, and comments.
• Programming practices and principles

Variable Names
Use camelCase for identifier names (variables and functions).

Camel case convention means typing the words in lower-case, only capitalizing the first
letter in each word.

All names start with a letter.

Spaces Around Operators


Always put spaces around operators ( = + - * / ), and after commas:

Code Indentation
Always use 2 spaces for indentation of code blocks:
Statement Rules
General rules for simple statements:

• Always end a simple statement with a semicolon.

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.

Naming Conventions
Always use the same naming convention for all your code. For example:

• Variable and function names written as camelCase


• Camel case convention, typing the words in lower-case, only capitalizing the first
letter in each word.
• Global variables written in UPPERCASE
• Constants (like PI) written in UPPERCASE

Hyphens are not allowed in JavaScript names.

File Extensions
HTML files should have a .html extension (not .htm).

CSS files should have a .css extension.

JavaScript files should have a .js extension.


Use Lower Case File Names
Initialize Variables
It is a good coding practice to initialize variables when you declare them.

This will:

• Give cleaner code


• Provide a single place to initialize variables
• Avoid undefined values

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy