The script tag takes two important attributes Language
Let us write our class example to print out “Hello World”.
Next, we call a function document .write which writes a string into our HTML document. This function can be used to write text, HTML, or both. So the above code will display the following result: Hello World! Whitespace and Line Breaks
Semicolons are optional
<!— var1=10 var2=20 //à
But when formatted in a single line as follows, the semicolons are required:
<!— var1=10; var2=20; //à
Note It is a good programming practice to use semicolons.
Script in <head> … </head> section
Script in <body> … <.body>
Section Script in <body> …. </body>
and <head> ….. </head> sections.
Script in and external file and then include in <head>--- </head> section.
If you want to have a script run on some event, such as when a user clicks somewhere, then you will place that script in the head as follows:
<!— Function sayHello() alert(“Hello World”) } //-- >
<input type=”button” onclick=”sayHello()” value=”Say Hello” />
<!— document.wirte(“Hello Word”) //-- > </script>
<p>This is webpage body </p>