04. Statements and Code Readability

Statements

When JavaScript interprets your code, it will go through it line by line to execute your code. Each line of execution is known as a statement.

As the proper developer, you should separate each statement with a semicolon.

Code blocks

Statements should be placed in blocks for organization and clarity.

Remember that programming is not just about making things work, but allowing others to read and understand your code. This often means that you should find a good middle-ground between a code's efficiency and readability.

Comment

Every so often you should include comments in JavaScript. This not only allows your colleagues to review your code, but you'll also spend much less time making sense of your own logic when you come back to your code months later.

Comments are also helpful to prevent execution of part of a code when you're trying to debug. Simply comment out the part you don't want to run.

// Comments precede a double slash
/*
Or go between the slash asterick notation like so
*/

White space

When executing statements, JavaScript ignores whitespaces. This means that the following two statements are identical:

var greeting = "Hello";
var greeting="Hello"  ;

It's better to opt for the former, which allows for better readability.

Aching back from coding all day?

Inversion Therapy Table

Aching back from coding all day? Try Back Problems

Stretch out your back and relieve your back muscles with inversion therapy. This device counteracts the forces of gravity on the body by decompressing and elongating the spine. By using this product just ten minutes a day, you can be well on your way to improved circulation and posture while relieving muscle aches, back pain and stress.

$$ Check price
119.98119.98Amazon 4.5 logo(1,700+ reviews)

More Back Problems resources

Build modern and responsive webpages

Responsive Typography

Build modern and responsive webpages Try Front-end

Responsive web design helps your site maintain its design integrity on a variety of screen sizes, but how does it affect your typography? With this practical book, graphic designers, web designers, and front-end developers alike will learn the nuts and bolts of how to get the best appearance from type without sacrificing performance on any device.

$ Check price
24.9924.99Amazon 4.5 logo(3+ reviews)

More Front-end resources

Ad