JavaScript code can be placed in an HTML file in three ways:
Inline JavaScript: Inline JavaScript is placed between the `<script>` and `</script>` tags in the HTML document. This is the simplest way to add JavaScript code to an HTML document, but it is not recommended for large amounts of code.
<html>
<head>
<title>Inline JavaScript</title>
</head>
<body>
<script>
console.log("Hello, world!");
</script>
</body>
</html>
External JavaScript: External JavaScript is placed in a separate file with the `.js` extension. The file is then referenced in the HTML document using the `<script>` tag's `src` attribute. This is the recommended way to add JavaScript code to an HTML document, as it makes the code more modular and easier to maintain.
html
<html>
<head>
<title>External JavaScript</title>
</head>
<body>
<script src="myscript.js"></script>
</body>
</html>
Combined JavaScript: Combined JavaScript is when the JavaScript code is placed in the same file as the HTML code. This is not recommended, as it can make the code difficult to read and maintain.
<html>
<head>
<title>Combined JavaScript</title>
</head>
<body>
<script>
console.log("Hello, world!");
</script>
</body>
</html>