JavaScript - Script Tag, Attributes and 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

<html>
 <head>
  <script type="text/javascript">
   function display(){
   alert ("Satya le Harish ko Billa Hanyo!!");
   }
  </script>
 </head>
 <body>
  <input type="button" onClick="display()" value="Harish ko Billa">
 </body> 
</html>

Output