JavaScript – Script Tag, Attributes, and Syntax

JavaScript Tag, Attribute & Syntax

The <script> tag is used to define the JavaScript code. It identifies the block of the script on the page.

The <script> tag loads the script file which has extensions [eg. .js, script.js], or the script code written inside the <script> tag.

Attributes of <script> Tag

Attribute Value Description
type media_type It specifies the media type of the script
src url It specifies the URL of the external file of JavaScript in the form of .js extension.
defer defer Specifies that the script is executed when the page has finished parsing support external script files.
charset charset Character encoding used in an external file of JavaScript.
XML:space preserve White space in code should be preserved
asyn async Specifies the script is executed asynchronously supports for external files.

The External JavaScript 

The external JavaScript file is embedded like as following in a web page.

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

HTML / JS Code

  <script type="text/javascript">
   function display(){
   alert ("Hello!");
  <input type="button" onClick="display()" value="How is That?">


About Author provides tutorials related to tech and programmings. We are also setting up a community for the users and students.

You may also like


JavaScript – Introduction, History, and Syntax

  • September 17, 2020
What is “JavaScript”? The first appearance of JavaScript was made in Netscape 2.0 in 1995 with a name Live Script.

JavaScript – Write Program to Print Hello World!!!

  • September 17, 2020
JavaScript is scripting language which is similar to C. It is syntax and logic are similar to C, C++ and