JavaScript is applied to your HTML page in 3 different ways
- Inline
- Internal
- External
Inline
When the JavaScript is written within the html element using attributes related to events of that element
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<form>
<input type="button" value="Click me" id="add" onclick="alert('See the click event has triggered')">
</form>
</body>
</html>
Output
![](https://i0.wp.com/chandanbhagat.com.np/wp-content/uploads/2022/01/image-1024x266.png?resize=640%2C166&ssl=1)
![](https://i0.wp.com/chandanbhagat.com.np/wp-content/uploads/2022/01/image-1024x266.png?resize=640%2C166&ssl=1)
![](https://i0.wp.com/chandanbhagat.com.np/wp-content/uploads/2022/01/image-1024x266.png?resize=640%2C166&ssl=1)
Internal
When the JavaScript is written within the script element anywhere in the HTML document, it is an internal JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
</body>
<script>
document.write('<h1>What a wonderful day</h1>')
</script>
</html>
Output
![](https://i0.wp.com/chandanbhagat.com.np/wp-content/uploads/2022/01/image-1-1024x302.png?resize=640%2C189&ssl=1)
![](https://i0.wp.com/chandanbhagat.com.np/wp-content/uploads/2022/01/image-1-1024x302.png?resize=640%2C189&ssl=1)
![](https://i0.wp.com/chandanbhagat.com.np/wp-content/uploads/2022/01/image-1-1024x302.png?resize=640%2C189&ssl=1)
External
When the JavaScript is written in a separate file and then linked to the html, it is known as External JavaScript.
HTML File
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
</body>
<script src="abc.js"></script>
</html>
JavaScript File
document.write('<h1>What a wonderful day</h1>');
Output
![](https://i0.wp.com/chandanbhagat.com.np/wp-content/uploads/2022/01/image-3-1024x544.png?resize=640%2C340&ssl=1)
![](https://i0.wp.com/chandanbhagat.com.np/wp-content/uploads/2022/01/image-3-1024x544.png?resize=640%2C340&ssl=1)
![](https://i0.wp.com/chandanbhagat.com.np/wp-content/uploads/2022/01/image-3-1024x544.png?resize=640%2C340&ssl=1)