Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Line Length < 80

For better readability, avoid lines longer than 80 characters.

If a JavaScript statement doesn’t fit on one line, it’s best to break it after an operator or a comma.

Example

document.getElementById(“demo”).innerHTML =
“Hello Dolly.”;

Naming Conventions

Always maintain consistency in your naming conventions across your code. For example:

  • Use camelCase for variable and function names.
  • Use UPPERCASE for global variables (though we don’t follow this convention, it is quite common).
  • Use UPPERCASE for constants (e.g., PI).

The choice between hyphens, camelCase, or underscores for variable names is often debated among programmers. The answer depends on who you ask:

In HTML and CSS:

  • HTML5 attributes can start with data- (e.g., data-quantity, data-price).
  • CSS properties use hyphens in their names (e.g., font-size).

Underscores:

Many programmers prefer using underscores (e.g., date_of_birth), particularly in SQL databases.

Underscores are also common in PHP documentation.

PascalCase:

PascalCase is commonly used by C programmers.

camelCase:

camelCase is the standard naming convention in JavaScript itself, as well as in libraries like jQuery and others.

Avoid starting names with a $ sign, as it may conflict with the naming conventions of many JavaScript libraries.