Javascript placement in HTML5 document

An HTML Page example showcasing how you can insert/link javascript scripts inside an HTML document.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Javascript placement in HTML document</title>
<script>
console.log("Script in HTML > head");
</script>
<script src="head.js"></script>
</head>
<body>
<script>
console.log("Script in HTML > body");
</script>
<script src="body.js"></script>
</body>
</html>

You can have javascript directly inside the document (head / body) and/or import it from external files (head/body).

You can find the file as a project at Github: Javascript-Cheatsheet / js-placement.