Let’s open the script.js file in a text editor and define the following code in it:
Here, the method is used to add some content to the web page document.write. The first call to the method document.write prints the title <h2>, and the second call prints plain text.
Now let’s include this file in the index.html web page :
Also, keep in mind that the opening script tag must be followed by a closing one.</script>
And after opening the index.html file in the browser, a message will be displayed:
We can reuse the same code across multiple web pages