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?

Self-Massage Tool

Aching back from coding all day? Try Back Problems

Relieve spasms, tight muscles, trigger points and pressure points with the Body Back Buddy! This trigger point massage is designed to help you self-message any area of your body - especially those that are hard to reach. Keeping your muscles relaxes and out of contraction is importan in helping to reduce pain and prevent muscle injury.

$ Check price
29.9529.95Amazon 4.5 logo(3,443+ reviews)

More Back Problems resources

Build modern and responsive webpages

HTML & CSS

Build modern and responsive webpages Try Front-end

This book teaches HTML as if it's for anyone - hobbyists, students, and professionals - and it's full-color throughout. It utilizes information graphics and lifestyle photography to explain the topics in a simple way that is engaging. You can progress through the chapters from beginning to end or just dip into topics of particular interest at your leisure.

$ Check price
29.9929.99Amazon 4.5 logo(926+ reviews)

More Front-end resources

Ad