Home >Web Front-end >HTML Tutorial >What happens if you misplace a semicolon in JavaScript?

What happens if you misplace a semicolon in JavaScript?

WBOY
WBOYforward
2023-08-30 09:13:06959browse

What happens if you misplace a semicolon in JavaScript?

If semicolons are placed in the wrong place in JavaScript, it can lead to misleading results. Let's look at an example where the if statement condition is false, but the value is printed because of a misplaced semicolon.

Example

<!DOCTYPE html>
<html>
   <body>
      <script>
         var val1 = 10;

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

         if (val2 == 15) {
            // this won&#39;t get printed
            document.write(val2);
         }
      </script>
   </body>
</html>

The above is the detailed content of What happens if you misplace a semicolon in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete