Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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