Why every statement level we are giving semicolon in Java Script ?
In programming language it is compulsory to write semicolon but in Scripting it is not compulsory.
If I executed with semicolon Perfectly executed :
If I executed without semicolon Perfectly executed :
Note: No Change in the Output
So Why Semicolon
When we write like this JavaScript interpreter unable to understand if you are writing two statement side by side. In this case you must need to separate by semicolon.
Output:
In programming language it is compulsory to write semicolon but in Scripting it is not compulsory.
If I executed with semicolon Perfectly executed :
<!doctype html>
<body>
<pre>
<script type="text/javascript" language="javascript">
document.write("JavaScript");
document.write("Coding Atharva");
</script>
</pre>
</body>
Output:<body>
<pre>
<script type="text/javascript" language="javascript">
document.write("JavaScript");
document.write("Coding Atharva");
</script>
</pre>
</body>
If I executed without semicolon Perfectly executed :
<!doctype html>
<body>
<pre>
<script type="text/javascript" language="javascript">
document.write("JavaScript")
document.write("Coding Atharva")
</script>
</pre>
</body>
Output:<body>
<pre>
<script type="text/javascript" language="javascript">
document.write("JavaScript")
document.write("Coding Atharva")
</script>
</pre>
</body>
Note: No Change in the Output
So Why Semicolon
<!doctype html>
<body>
<pre>
<script type="text/javascript" language="javascript">
document.write("JavaScript") document.write("Coding Atharva")
</script>
</pre>
</body>
Output:<body>
<pre>
<script type="text/javascript" language="javascript">
document.write("JavaScript") document.write("Coding Atharva")
</script>
</pre>
</body>
When we write like this JavaScript interpreter unable to understand if you are writing two statement side by side. In this case you must need to separate by semicolon.
<!doctype html>
<body>
<pre>
<script type="text/javascript" language="javascript">
document.write("JavaScript");document.write("Coding Atharva")
</script>
</pre>
</body>
<body>
<pre>
<script type="text/javascript" language="javascript">
document.write("JavaScript");document.write("Coding Atharva")
</script>
</pre>
</body>
Output: