loader

Loading

CoderrShyam logo

CoderrShyam

HomeAboutContactBlogTutorials
LoginSignup

Introduction

Quick StartWhat is JavaScriptHistory of JavaScript

Setup

Node.js InstallationVisual Studio Code

Basics

Syntax & Comments
Statements, Semicolons, and WhitespaceComments
Variables
Functions

Advanced

CoderrShyam logo

CoderrShyam

HomeAboutContactBlogTutorials
LoginSignup
TutorialsJavaScript TutorialSyntax & CommentsStatements, Semicolons, and Whitespace

Statements, Semicolons, and Whitespace

Understand how JavaScript statements, semicolons, and whitespace work together.

Statements

A statement is a single instruction the JavaScript engine can execute. For example:

console.log("Hello, World!");

Statements can declare variables, call functions, or perform calculations.

Good to Know

JavaScript runs statements in order, from top to bottom.

Semicolons

Semicolons end statements. JavaScript can sometimes insert them for you, but adding them explicitly is best practice.

let age = 18;

Style guides like Airbnb or Google generally recommend always using semicolons.

You can also place multiple statements on the same line if you separate them with semicolons:

let x = 10;
let y = 20;
console.log(x + y);

Whitespace

Whitespace is any space, tab, or blank line in your code. JavaScript ignores extra whitespace, letting you format code for readability. These are identical in functionality:

let name = "Shyam"; // best practice

This is why consistent whitespace matters:

  • Makes code easier for humans to scan
  • Avoids confusion in teamwork
  • Follows industry style guides

Therefore, remove any extra whitespaces from code and make it more readable:

let name = "Shyam"; 
let name = "Shyam"; 

Tip

Avoid mixing tabs and spaces randomly; stick to a consistent style.

Line Breaks

JavaScript separates statements using line breaks, but automatic semicolon insertion can sometimes cause mistakes. Always using semicolons is safer:

If you leave out semicolons, JavaScript might still work thanks to automatic semicolon insertion, but it's riskier:

let score = 42;
console.log(score);

This can lead to unexpected behavior, especially in complex code. Always using semicolons is safer and clearer.

How is this guide?

March 7th, 2026

Syntax & Comments

Learn how JavaScript statements and comments work to structure your code.

Comments

Learn how to use comments to explain and document your JavaScript code.

© 2026CoderrShyamAll Rights Reserved.

On this page

Statements
Semicolons
Whitespace
Line Breaks
Follow us on GitHub