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

What happens if you misplace a semicolon in JavaScript?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-08-30 09:13:06
forward
995 people have browsed it

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>
Copy after login

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!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template