Tuesday, October 21, 2014

Javascript Blocks and Comments

JavaScript Blocks:

- JavaScript statements can be grouped together in blocks.
- Blocks start with a left curly bracket {, and ends with a right curly bracket }.
- The purpose of a block is to make the sequence of statements execute together.
<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>
- Normally a block is used to group statements together in a function or in a condition   
(where a group of statements should be executed if a condition is met).

Comments in JavaScript:
- JavaScript comments can be used to make the code more readable.
- Comments can be added to explain the JavaScript, or to make the code more readable.
1)Single line comments start with //.
2)Multi line comments start with /* and end with */.
3)The following example uses a multi line comment to explain the code:


No comments: