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.

Build modern and responsive webpages

The Modern Web

Build modern and responsive webpages Try Front-end

The Modern Web will guide you through the most important tools of device-agnostic web development, including HTML5, CSS3, and JavaScript. The plain-english explanations and practical examples emphasize the techniques, principles, and practices that you'll need to easily transcend individual browser quirks and stay relevant as these technologies are updated.

$ Check price
34.9534.95Amazon 4.5 logo(30+ reviews)

More Front-end resources

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

Ad