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?

Acupressure Mat & Pillow

Aching back from coding all day? Try Back Problems

Relieve your stress, back, neck and sciatic pain through 1,782 acupuncture points for immediate neck pain relief. Made for lower, upper and mid chronic back pain treatment, and improves circulation, sleep, digestion and quality of life.

$$ Check price
144.87144.87Amazon 4.5 logo(1,890+ reviews)

More Back Problems resources

Build modern and responsive webpages

JavaScript & JQuery

Build modern and responsive webpages Try Front-end

This book was written for anyone who wants to use JavaScript to make their websites a little more interesting, engaging, interactive, or usable. In particular, it is aimed at people who do not have a degree in computer science (well, not yet anyway).

$ Check price
39.9939.99Amazon 4.5 logo(385+ reviews)

More Front-end resources

Ad