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?

Foam Seat Cushion

Aching back from coding all day? Try Back Problems

This foam seat cushion relieves lowerback pain, numbness and pressure sores by promoting healthy weight distribution, posture and spine alignment. Furthermore, it reduces pressure on the tailbone and hip bones while sitting. Perfect for sitting on the computer desk for long periods of time.

$ Check price
99.9599.95Amazon 4.5 logo(9,445+ 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