3D Gallery with Great Artwork Imagine Logo with Three Colors Beach Cabin 3D Android Tablet with Different Screens Studio Apartment Red Figured Greek Vase on Blue Background Silver and Gold Flashlight Lake on Fire

JavaScript: Code Quality

Page 16

Code Quality

Introduction Code Quality Spaces Between Operators Statements Line Breaks Variable Placement Naming Conventions Minimize Types: String, Number, Boolean Objects Summary

Introduction

Code quality includes a number of different techniques. This page lists various best practices, recommended by others, with JavaScript code examples.

Code Quality

Quality coding practices help improve legibility and reduce bugs. See examples of the following topics, spaces, statements, line breaks, variable placement, naming conventions and minimize use of String, Number and Boolean variables.

Spaces Between Operators

Recommended:

a + b = c;

Not recommended:

a+b=c;

Statements

Statements and expressions should end in semicolors - ;, however they're not necessary. It's just good practice.

Line Breaks

For legible code avoid lines longer than eighty characters. Insert line breaks after operators, when possible.

Variable Placement

Place all variables at the beginning of the script. This practice assists understanding of a script.

Variable Naming

Programmers commonly name private variables with a leading underscore. Generally JavaScript doesn't include private variables. All variables are public. However some workarounds exist.

_privateName = "Sonjia";

Naming Conventions

JavaScript programmers generally apply camelCase when naming a variable, function or method. Camelcase assigns a lower case to the first letter of a variable and upper case to separate words within a variable. For example:

showAlert(), catName, webDeveloper

Minimize Types

String, Number, Boolean Objects

The following declarations might seem clear, as far as data types, yet they decrease code execution speed. Minimize creation of new String, Number and Boolean types.

a = new String();
b = new Number();
c = new Boolean();

Summary

Code quality includes a number of different techniques. This page lists various best practices, recommended by others, with JavaScript code examples.

Code Quality

Quality coding practices help improve legibility and reduce bugs. You saw examples of the following topics, spaces, statements, line breaks, variable placement, naming conventions and encouragment to minimize use of String, Number and Boolean variables.

Learn JavaScript

JavaScript's the foundation of Web developer and Website design skills. This free and unique JavaScript tutorial includes some new or seldom used, but useful features.

Tags
canvas drawing, web design, web designing course, how to become a web developer, coding websites, website developers,learning web design, html web design, html5 canvas tutorials, coding Website, html5 canvas, learn to code, html5 canvas tutorial,learn html tutorial, simple html tutorial

Ads >
Create 3D Games: Learn WebGL Book 2 Simple Shaders: Learn WebGL Book 4
3D Programming for Beginners: Learn WebGL Book 1

for Web graphics!

Copyright © 2022 Amy Butler. All Rights Reserved.