where can you write javascript code ?


 we can write javascript code :

  1. Any where in the HTML file between <script> </script> tags .
  2. As the value of the event handler attributes
 
  • writing js code Between  <script> </script> tags , it may be internal or external . 
  • external by using src attribute in the script open tag <script> .


External JavaScript  code Advantages :

  • It separates HTML and code.
  • It makes HTML and JavaScript easier to read and maintain.
  • Cached JavaScript files can speed up page loads.

 

 

Note : 

  1. Placing scripts at the bottom of the <body> element improves the display speed, because script interpretation slows down the display.
  2. we can write HTML mark ups inside js code by writing these HTML tags as a string , between " " double qoutes .
  3. Old JavaScript examples may use a type attribute: <script type="text/javascript"> ,The type attribute is not required. JavaScript is the default scripting language in HTML.

Comments

Popular posts from this blog

Variable Scope in javascript

Shadowing

Hoisting