JavaScript White Space

Semicolons separate JavaScript statements. Add a semicolon at the end of each executable statement:
    <script>
        a = 1;
        b = 2;
        c = a + b;
        document.getElementById("demo1").innerHTML = c;
    </script>

When separated by semicolons, multiple statements on one line are allowed:
    <script>
        a = 1; b = 2; c = a + b;
        document.getElementById("demo1").innerHTML = c;
    </script>

JavaScript ignores multiple spaces. You can add white space to your script to make it more readable. The following lines are equivalent:

    var person="Hege";
    var person = "Hege";

Good habit A good practice is to put spaces around operators ( = + - * / ). For example: var x = y + z;
Back Table of Contents Next