Which attribute is used in an HTML tag to link to an external JavaScript file?

Prepare for the Web Development 201 Test. Utilize our flashcards and multiple choice questions with hints and explanations. Ensure you're ready for your web development exam!

The attribute used in an HTML tag to link to an external JavaScript file is the source attribute, identified as "src." When an HTML file references an external JavaScript file, the "src" attribute is included within the script tag, allowing the browser to fetch and execute the JavaScript code contained in the specified file.

For example, the following code snippet demonstrates how to correctly link to an external JavaScript file:


<script src="extFile.js"></script>

In this context, "extFile.js" is the name of the external JavaScript file. The "src" attribute points to the location of the file, indicating where the browser should look to find the JavaScript code.

The other attributes mentioned do not serve the purpose of linking to external JavaScript files. The "file" attribute does not exist in HTML specifications as a valid way to link scripts, and "href" is primarily used for linking to external resources like stylesheets or web pages but not for JavaScript files. As for the "script" attribute, it is not a standard attribute for linking JavaScript files; rather, "script" is the element itself that encompasses the "src" attribute.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy