JavaScript, also referred to as JS, is one of the client-side scripting languages that is usually used in web development to create modern and interactive web pages. The term “script” is used to refer to languages that are not inherently standalone in nature. In this case, it refers to the fact that JavaScript runs on the client machine.
In other words, it can also be said that the term “scripting” is used for languages that need the support of another language to get executed. For example, JavaScript programs will not get executed without the help of HTML or if they are integrated into an HTML code.
JavaScript is used in a wide range of ways when it comes to web pages, such as build image galleries, generating warning messages, manipulation of DOM, form validation, etc.
Users can easily add JavaScript to HTML pages using an embedding code. In order to add JavaScript code into the HTML pages, use the <script>…..</script> tag of the HTML that gets wrapped around JavaScript code while inside the HTML program.
Users can also define JavaScript code in either the <body> tag – also known as body tag – or <head> tag owing to the fact that it entirely depends on the structure of the web page that the users decide to use.
This can be understood more clearly with the help of an example of adding JavaScript to HTML, as shown below.
Input:Â
<!DOCTYPE html >
<html>
<head>
<title> page title</title>
<script>
document.write(“Welcome to Javatpoint”);
</script>
</head>
<body>
<p>Inthis example we saw how to add JavaScript in the head section </p>
</body>
</html>
Output:Â
As mentioned above, you can also define the JavaScript code in the <body> tags or body section.
Input:
<!DOCTYPE html >
<html>
<head>
<title> page title</title>
</head>
<body>
<script>
document.write(“Welcome to Javatpoint”);
</script>
<p> In this example we saw how to add  JavaScript in the body section </p>
</body>
</html>
Output: