Javascript - Introduction Statements

Introduction

Statements in ECMAScript are terminated by a semicolon.

Omitting the semicolon makes the parser determine where the end of a statement occurs.

var sum = a + b        //valid even without a semicolon - not recommended 
var diff = a - b;      //valid - preferred 

Multiple statements can be combined into a code block by using C-style syntax, beginning with a left curly brace ({) and ending with a right curly brace (}):

if (test){ 
    test = false; 
    console.log(test); 
} 

Control statements, such as if, require code blocks only when executing multiple statements.

It is considered a best practice to always use code blocks with control statements, even if there's only one statement to be executed:

if (test) 
    console.log(test);     //valid, but error-prone and should be avoided 
                     
if (test){           //preferred 
    console.log(test); 
}