JS Statements : in JavaScript

Statement in JavaScript :

  1. Firstly check whether JS is enabled in Browser or not (Mozilla | IE | Opera)
  2. Executable single line of Script is called as Statement in JavaScript.
  3. JavaScript Code contain sequence of statements that are executed by browser.
  4. Every Executable JavaScript Statements is terminated by semicolon (optional)
  5. Statement is a command to a browser.

Type of JavaScript Statements –

  1. Conditional Statement [i.e If-else Statement]
if( marks > 40 ){
   document.write("<b>Status : Pass</b>");
  1. Declaration Statement
var ivar;
  1. Assignment Statement
ivar = 100;
  1. Executable Statement
document.write("Hello JavaScript");

Some Rules of JavaScript Statements

  1. JavaScript Statement is case Sensitive
  2. JavaScript Statement ends with semicolon (optional)
  3. JavaScript Statement may contain HTML Tags.
  4. JavaScript Statements can be embedded inside block

consider one by one scenario –

1. JavaScript is case Sensitive

JavaScript is case sensitive, variable name used in lower case should be accessed using same case. Consider the following example where we have changed the case of method name.

Error No 1 :

document.Write("Hello JS");

this statement will throw error.instead it should be like this –

document.write("Hello JS");

In the below example we have changed the case of variable.

Error No 2 :

var message;

message and Message will be considered as two different variables.

2. JavaScript Statement ends with semicolon (optional)

  1. According to the JavaScript standard ,semicolon is optional .
  2. The browser is supposed to interpret the end of the line as the end of the statement.
  3. Because of this you will often see examples without the semicolon at the end.

3. JavaScript Statements can be embedded inside block

  1. Pair of Curly braces is used to embed JavaScript Statements.
  2. Once embedded in Pair , Group of JavaScript Statements is called as “Group“.
<script type="text/javascript">
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
document.write("<p>This is another paragraph.</p>");

JavaScript Statements may contain HTML Tags as shown in Program.

Examples of Statements :

In the upcoming chapters we will be learning the more such articles on JS Statements –