Javascript is a programming language, that has two main uses:
Today we are focusing on (1).
More specifically, what are the different ways you can include your Javascript in a page run by a web browser?
Code can either be included inline (part of the page) or included via external link (URL to resource)
<script type="text/javascript">
const a = 1 + 2;
console.log(a);
</script>
<script type="text/javascript" src="mywork.js">
</script>
const a = 1 + 2;
console.log(a);
inline
external
mypage1.html
mypage2.html
mywork.js
Linking javascript externally:
Placing Javascript inline:
<html>
<head>
<!-- CAN INCLUDE IN HEADER -->
</head>
<body>
<!-- CAN INCLUDE IN TOP OF THE BODY -->
<!-- MOST OF YOUR PAGE -->
<!-- CAN INCLUDE IN BOTTOM OF THE BODY -->
</body>
</html>
Generally speaking you can either:
We usually do (2)