where to put js in html code example

Example 1: how to put javascript in HTML

<script>
  //put your java script here
  </script>

Example 2: html bind js file

<script type="text/javascript" src="path-to-javascript-file.js"></script>

Example 3: best place to include script in html layout

JavaScript in <head> or <body>
You can place any number of scripts in an HTML document. Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.

Example 4: How to add js file to a site through url

var jsFile = document.createElement("script");
jsFile.src = "homePage.js";  // it can be path also  "{themes('/scripts/homePage.js')}"
document.body.appendChild(jsFile);  //append it as src to body