Home >Web Front-end >HTML Tutorial >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.
<!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'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!