JavaScript Statements and Semicolons


In JavaScript, every instruction you write is called a statement. Statements tell the browser what action to perform, such as displaying text, storing values, or performing calculations.

Semicolons are used to mark the end of a statement. While JavaScript can sometimes run without semicolons, using them is a good practice because it makes your code clearer and helps avoid unexpected errors.

Why Use Semicolons?

  • They clearly separate one statement from another  
  • They reduce the chances of logical errors 
  • They make code easier to read and maintain  
  • They follow professional coding standards  

Using semicolons is a habit that every good developer should build from the beginning.

This example uses semicolons to end each statement. The code is clear, easy to read, and follows good coding practice.

Each line performs one action, and the semicolons show where each instruction ends.

This code may still work because JavaScript automatically adds semicolons in some cases. This feature is called Automatic Semicolon Insertion.

However, relying on this can sometimes cause bugs. That is why professional developers prefer to write semicolons themselves.

This example shows that multiple statements can be written on one line, but it is not recommended for beginners.

Writing one statement per line with proper semicolons makes your code cleaner, easier to debug, and more professional.