JavaScript is a dynamic programming language commonly used to add interactivity and functionality to web pages. When used with HTML, JavaScript can manipulate HTML elements, respond to user actions, and perform various tasks on a web page.
<html>
<head>
<script>
function greet() {
alert("Hello, World!");
}
</script>
</head>
<body>
<button onclick="greet()">Click Me</button>
</body>
</html>
An inline script in HTML refers to JavaScript code that is placed directly within the HTML document using the <script> element. Inline scripts are typically used for small, specific functions or event handlers within the HTML file.
<html>
<body>
<button onclick="alert('Hello, Inline Script!')">Click Me</button>
</body>
</html>
An internal script in HTML is JavaScript code that is embedded within the <script> tags within the HTML document. It is usually placed in the <head> or <body> section of the HTML file. Internal scripts are suitable for more extensive JavaScript functions or scripts that need to be reused across multiple pages of a website.
<html>
<head>
<script>
function calculateSum(a, b) {
return a + b;
}
</script>
</head>
<body>
<p>The sum of 5 and 3 is: <span id="result"></span></p>
<script>
document.getElementById("result").textContent = calculateSum(5, 3);
</script>
</body>
</html>