0% found this document useful (0 votes)
102 views

Statements in Javascript

Statements are programming instructions in JavaScript that are executed one by one in the order they are written. Semicolons separate statements and are recommended but not required. Comments are used to explain code and prevent execution for testing. Single line comments start with // and multi-line comments start with /* and end with */. Comments are a good practice to make code more readable.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views

Statements in Javascript

Statements are programming instructions in JavaScript that are executed one by one in the order they are written. Semicolons separate statements and are recommended but not required. Comments are used to explain code and prevent execution for testing. Single line comments start with // and multi-line comments start with /* and end with */. Comments are a good practice to make code more readable.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

1var a, b, c;     // Declare 3 variables


2a = 5;           // Assign the value 5 to a
3b = 6;           // Assign the value 6 to b
4c = a + b;       // Assign the sum of a and b to c
When separated by semicolons, multiple statements on one line are allowed:

1a = 5; b = 6; document.write("<h1>Hello World</h1>") ;

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.

1//document.write("<h1>Hello World 1</h1>")


2document.write("<h1>Hello World 2</h1>")
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.

1/*
2document.write("<h1>Line 1</h1>");
3document.write("Line 2")
4*/
Using comments whenever necessary is always a good practice and in real world scenarios it is many times necessary.

You might also like