Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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.
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't get printed
document.write(val2);
}
</script>
</body>
</html> Advertisements
