Statements in Javascript
Statements 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.
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.
Example –
In the example below, the first line – “Hello World 1” will not be executed.
Example –
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.