A JavaScript statement is a command to
a web browser to perform specific task define (program written) by the
user. JavaScript Statements are written with the set of elementary
rules that specifies how to write JavaScript programs. A JavaScript
program is a set of one or more statements. A statement will have
internal components like Variables, Literals, Identifier, reserved
keywords, Comments, conditional statement, Arrays, Functions, Objects,
Classes etc
JavaScript is case sensitive, in the
most of cases JavaScript Statements terminated with a semicolon(;) or
with Returns(Enter or line-break). Even though semicolon is optional,
JavaScript Statements terminated with a semicolon(;) is the best
practice of JavaScript programming.
var txtName="I love JavaScript";
var intNum=10
semicolons allows us to group multiple statements on one line.
x = x + 1; y = 20; z = x+y;
As the semicolon is optional, we can represent above statements separated with a line-break.
x = x + 1
y = 20
z = x+y
Categories of JavaScript Statements
Depending on the task a statement perform, they are categories as:
- Conditional Statements
- Loop Statements
- Object Manipulation Statements
- Comment Statements
- Exception Handling Statements
JavaScript Blocks - Group of JavaScript Statements
JavaScript statements can be grouped
together in blocks. Curly braces ({ }) are used to group a list of
statements together in blocks. JavaScript block helps to execute
sequence of statements together to perform a specific task. JavaScript
block are the integral part of the function and conditional loops.
<script type="text/javascript">
for (x=0; x < 10; x++)
{
document.write("x="+ x +"<br>");
}
</script>
Some Tips on declaring a JavaScript Statement
- JavaScript programs are written using the Unicode character set.
- JavaScript is a case-sensitive language so take care while defining and using variables, function names.
- Do not use reserved keywords as variables, function names.
- JavaScript ignores spaces, tabs, and newlines that appear between
tokens in programs so indent your programs as per your consistency.
- Omitting semicolons is not a good programming practice; you should get in the habit of using them.
|