JS Statements : in JavaScript
Statement in JavaScript :
- Firstly check whether JS is enabled in Browser or not (Mozilla | IE | Opera)
- Executable single line of Script is called as Statement in JavaScript.
- JavaScript Code contain sequence of statements that are executed by browser.
- Every Executable JavaScript Statements is terminated by semicolon (optional)
- Statement is a command to a browser.
Type of JavaScript Statements -
- Conditional Statement [i.e If-else Statement]
if(condition) { ------ ------ }
- Declaration Statement
var ivar;
- Assignment Statement
ivar = 100;
- Executable Statement
document.write("Hello JavaScript");
Some Rules of JavaScript Statements
[checklist]- JavaScript Statement is case Sensitive
- JavaScript Statement ends with semicolon (optional)
- JavaScript Statement may contain HTML Tags.
- JavaScript Statements can be embedded inside block
1. JavaScript is case Sensitive
Error No 1 :
document.Write("Hello JS");
this statement will throw error.instead it should be like this -
document.write("Hello JS");
Error No 2 :
var message; document.write(Message);
message and Message will be considered as two different variables.
2. JavaScript Statement ends with semicolon (optional)
- According to the JavaScript standard ,semicolon is optional .
- The browser is supposed to interpret the end of the line as the end of the statement.
- Because of this you will often see examples without the semicolon at the end.
3. JavaScript Statements can be embedded inside block
- Pair of Curly braces is used to embed JavaScript Statements.
- 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>"); } </script>
JavaScript Statements may contain HTML Tags as shown in Program.