script tag is used to add javascript code or external javascript file. It is a paired tag. It can be placed in head or body section or as external file.

In Head Section

Writing javascript in head section allows to makes changes only in single or current HTML page. small piece of javascript code can be written in head section. With multiple webpage code duplicacy or repetition happens, and it makes error hard to find and time consuming also.

<!DOCTYPE html>
<html>
<head>
<script>
function functionInHead() {
    alert("javascript placed in head section");
}
</script>
</head>
<body>
<button type="button" onclick="functionInHead()">Click</button>
</body>
</html>

In body Section

Same as head section.

<!DOCTYPE html>
<html>
<body>
<button type="button" onclick="functionInBody()">Click</button>
<script>
function functionInBody() {
    alert("javascript placed in Body section");
}
</script>
</body>
</html>

In External File

Using external javascript file is a good practice, Multiple webpages of website can be handled easily with no code duplicacy or repetition.

Error finding is easier comparing to head and body section javascript implementation.

<!DOCTYPE html>
<html>
<head>
<script src="ext.js"></script>
</head>
<body>
<button type="button" onclick="functionInFile()">Click</button>
</body>
</html>