Statements & Comments in JavaScript

In this tutorial post we will understand what are statements & comment in JavaScript.

Statements in JavaScript –

A computer program is a list of “instructions” to be “executed” by a computer. In a programming language, these programming instructions are called statements.  JavaScript program is a list of programming statements.

Most JavaScript programs contain many JavaScript statements. The statements are executed, one by one, in the same order as they are written.

Semicolons (;)

Semicolons separate JavaScript statements. On the web, you might see examples without semicolons.
Ending statements with semicolon is not required, but highly recommended.

When separated by semicolons, multiple statements on one line are allowed:

JavaScript Comments –

JavaScript comments can be used to explain JavaScript code, and to make it more readable. JavaScript comments can also be used to prevent execution, when testing alternative code.

Single Line Comments –

Single line comments start with //.
Any text between // and the end of the line will be ignored by JavaScript (will not be executed).

Example –

In the example below, the first line – “Hello World 1” will not be executed.

Multi-line Comments –

Multi-line comments start with /* and end with */.
Any text between /* and */ will be ignored by JavaScript.

Example –

In the example below, both the lines will not be executed.

Using comments whenever necessary is always a good practice and in real world scenarios it is many times necessary.

Leave a Reply

Your email address will not be published. Required fields are marked *