5. How to use JavaScript in your web page?


Using the <script> element

          JavaScript codes run from inside a web page and type directly as a separate part of the web page file. The JavaScript programs found in a web page is called a script. Once the web browser encounters a script element, it interprets the statements that the element contains in its scripting engine.

          Script can be embedded or placed in an external file right into a document and connected to a page like CSS. The <script> element uses both methods.

Embedded <script>

          The code must be added as the content of a <script> element to embed a script on a page.


<script>

          Your code here

</script>

External <script>


<script src="external_script.js"></script>

          The benefits of using external script file is the application of the same script to different websites. Each external script, on the other hand, requires an additional server HTTP request, which slows down performance.