User Rating: 2 / 5

Star ActiveStar ActiveStar InactiveStar InactiveStar Inactive
 

JavaScript statements is the command that ordered JavaScript. Operations in the order they were placed. A written order to end or end commands with semi colon (;). Semicolon separates JavaScript statements. Normally you add a semicolon at the end of each executable statement. Using semicolons also makes it possible to write many statements on one line.

Example:

<html>
<body>
<p id="demo">JavaScript Tutorial.</p>
<div id="myDIV">www.Mindphp.com</div>
<script>
document.getElementById("demo").innerHTML="Learn more";
document.getElementById("myDIV").innerHTML="Mindphpwebsite";
</script>
</body>
</html>

This is the result:

 

JavaScript Code Blocks

JavaScript statements can be grouped together in blocks.

Blocks start with a left curly bracket, and end with a right curly bracket.

The purpose of a block is to make the sequence of a statements execute together.

A good example of statements grouped together in blocks, are JavaScript functions.

 

Example: "This example will run a function that will manipulate two HTML elements:

<html>
<body>
<p id="myPar">www.MindPHP.com</p>
<div id="myDiv">MindPHP</div>
<p>
<button type="button" onclick="myFunction()">Click Here</button>
</p>
<script>
function myFunction()
{
document.getElementById("myPar").innerHTML="Forums";
document.getElementById("myDiv").innerHTML="Tutorials";
}
</script>
<p>When you click on "Click Here", the two elements will change.</p>
</body>
</html>

This is the result:

 

 

Next

Chapter 5 - JavaScript Comments