Instead of wandering through loads of the theory , we will prefer to discuss the way of the JavaScript writing code in HTML page. JavaScript is written between <script> </script> tag , either in the <head> tag or in <body> tag.
<html>
<head>
<title> Including JavaScript to HTML Page</title>
<script type="text/javascript">
alert("Welcome to CodingPk JavaScript Tutorials");
</script>
</head>
</html>
Output:
• If we are writing the code in the HTML file or same web file etc .html , .php etc then we will write the code in <script> tag.
• If we want to include the external JavaScript file then we will include by following way.
<script src="javascriptfile.js"></script>
In the .js file, we will not write the JavaScript code in <script> tags we need to write the above JavaScript code by just following code:
alert("Welcome to CodingPk JavaScript Tutorials");
We wrote the JavaScript code in external JavaScript file without the <script> tag.
In the next Chapter we are going to discuss the JavaScript on-click function.