how to run a js file with html simple code example

Example 1: include script in html

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

Example 2: javascript hello world

I would do something like this:

<script>
  alert("Hello World!");
</script>

Example 3: calling javascript file in html

<script type="text/javascript" src="yourfile.js"></script>

Example 4: print hello world in javascript

console.log("Hello, World!");

console.error("Error, World!"); // For errors

console.warn("Warning, World!"); // For warnings

console.clear(); // To clear the console

Tags:

Html Example