How do you include external JavaScript in an HTML document?

Enhance your HTML skills with our HTML Tags Test. Challenge your expertise through interactive flashcards and multiple-choice questions. Each question includes hints and thorough explanations. Prepare effectively for your HTML examination!

Including external JavaScript in an HTML document is achieved by using the <script> tag with the src attribute. This method allows you to reference an external JavaScript file by providing its URL within the src attribute of the <script> tag. By doing so, the browser fetches and executes the JavaScript code from that external file, enabling modular JavaScript programming and keeping the HTML clean and organized.

This approach is preferred because it allows for better caching of JavaScript files and the ability to reuse scripts across different HTML documents without duplicating code. It also helps in maintaining a separation of concerns, where HTML structure is kept separate from JavaScript behavior, making the overall development process more efficient.

The other options do not conform to the standard method for integrating external JavaScript into HTML. For instance, the use of <js> is not a recognized HTML tag, and the <link> tag is for linking stylesheets, not scripts. Using the <script> tag without src or using import is incorrect in this context because these methods do not enable linking to an external JavaScript file appropriately.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy