Coding

JavaScript Code Blocks – JavaScript Tutorial

Task

JavaScript Code Blocks

Description

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>
<script>
function myFunction() {
    document.getElementById("demo1").innerHTML = "Hello World!";
    document.getElementById("demo2").innerHTML = "How are you?";
}
</script>
Try It Yourself - Online Compliler >>