What will happen if a semicolon is misplaced in JavaScript?

If a semicolon is misplaced in JavaScript, then it may lead to misleading results. Let’s see an example, wherein the if statement condition is false, but due to misplaced semi-colon, the value gets printed.


<!DOCTYPE html>
         var val1 = 10;

         if (val1 == 15) {
            document.write("Prints due to misplaced semi-colon: "+val1);
         var val2 = 10;

         if (val2 == 15) {
            // this won't get printed