JavaScript Code Blocks – JavaScript Tutorial


JavaScript Code Blocks


JavaScript statements can be grouped together in the code blocks, inside curly brackets { }.
The purpose of code blocks is to define the statements to be executed together.
One place you will find statements grouped together in the blocks, is in JavaScript functions:

Example 1

<p id="demo1"></p>
<p id="demo2"></p>
function myFunction() {
    document.getElementById("demo1").innerHTML = "Hello World!";
    document.getElementById("demo2").innerHTML = "How are you?";
Try It Yourself - Online Compliler >>