No icon

JAVASCRIPT STRUCTURAL EXECUTION

JAVASCRIPT STRUCTURAL EXECUTION

JAVASCRIPT STRUCTURAL EXECUTION 

In This topic we will clearly know the excecution procedure of external javascript;

Example : In below example we write a JAVASCRIPT in external file with id which is defined in html code, if you place these JAVA SRIPT before declaring of id which is used in javascript then code will not work properly, in this scenario we use these external javascript after declaration of id which is using in javascript code

Example 1 : It shows wrong placing of External  JavaScript Code Insertion

<html> 
<head>
    
SCRIPT  src="my.js"

SCRIPT


</head>

<body>


   DIV id="amd"  /DIV
   
</body>

</html>

Example 2 : It shows correct placing of External  JavaScript
<html> 
<head>
 </head>

<body>


   DIV id="amd" /DIV
   

   SCRIPT  src="my.js"

   SCRIPT

 

</body>

</html>

By default javascript code insertion is async it means it will execute step by step how we write a code 

By Defining defer attribute in script tag we can solve the above problem , Actually defer says that first executes the html code and next execute the javascript. 

 

Comment As:

Comment (0)